refactor!: removed plugin-iconify

This commit is contained in:
pengzhanbo 2024-07-23 00:28:58 +08:00
parent fa06931985
commit f32511be6a
12 changed files with 4 additions and 321 deletions

View File

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (C) 2021 - PRESENT by pengzhanbo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -1,47 +0,0 @@
# `@vuepress-plume/plugin-iconify`
添加 `iconify` 图标库支持。并注入全局组件 `<Iconify>`
## Install
```sh
npm install @vuepress-plume/plugin-iconify
# or
pnpm add @vuepress-plume/plugin-iconify
# or
yarn add @vuepress-plume/plugin-iconify
```
## Usage
``` js
// .vuepress/config.[jt]s
import { iconifyPlugin } from '@vuepress-plume/plugin-iconify'
export default {
// ...
plugins: [
iconifyPlugin()
]
// ...
}
```
## Options
```ts
interface IconifyOptions {
/**
* 组件名, 默认 `Iconify`
*/
componentName?: string
color?: string
size?: string | number
}
```
## Component
```vue
<Iconify name="material-symbols:home" color="currentColor" size="1em" />
```

View File

@ -1,51 +0,0 @@
{
"name": "@vuepress-plume/plugin-iconify",
"type": "module",
"version": "1.0.0-rc.81",
"description": "The Plugin for VuePress 2 - iconify",
"author": "pengzhanbo <volodymyr@foxmail.com>",
"license": "MIT",
"homepage": "https://github.com/pengzhanbo/vuepress-theme-plume#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/pengzhanbo/vuepress-theme-plume.git",
"directory": "plugins/plugin-iconify"
},
"bugs": {
"url": "https://github.com/pengzhanbo/vuepress-theme-plume/issues"
},
"exports": {
".": {
"types": "./lib/node/index.d.ts",
"import": "./lib/node/index.js"
},
"./package.json": "./package.json"
},
"main": "lib/node/index.js",
"types": "./lib/node/index.d.ts",
"files": [
"lib"
],
"scripts": {
"build": "pnpm run copy && pnpm run tsup",
"clean": "rimraf --glob ./lib",
"copy": "cpx \"src/**/*.{d.ts,vue,css,scss,jpg,png}\" lib",
"tsup": "tsup --config tsup.config.ts"
},
"peerDependencies": {
"vuepress": "2.0.0-rc.14"
},
"dependencies": {
"@iconify/vue": "^4.1.2",
"vue": "^3.4.33"
},
"publishConfig": {
"access": "public"
},
"keyword": [
"VuePress",
"vuepress plugin",
"iconify",
"vuepress-plugin-iconify"
]
}

View File

@ -1,78 +0,0 @@
<script lang="ts" setup>
import { Icon as OfflineIcon } from '@iconify/vue/offline'
import { ClientOnly } from 'vuepress/client'
import type { IconifyRenderMode } from '@iconify/vue'
import type { StyleValue } from 'vue'
import { computed, toRefs } from 'vue'
import { useIconify } from '../composables/index.js'
const props = withDefaults(
defineProps<{
name?: string
size?: string | number
color?: string
mode?: IconifyRenderMode
style?: StyleValue
flip?: string
vFlip?: boolean
hFlip?: boolean
inline?: boolean
rotate?: number
}>(),
{
name: '',
size: '',
color: '',
},
)
const { name } = toRefs(props)
const { icon, loaded } = useIconify(name)
const size = computed(() => {
const size = props.size || __VP_ICONIFY_SIZE__
if (String(Number(size)) === size)
return `${size}px`
return size
})
const color = computed(() => props.color || __VP_ICONIFY_COLOR__)
const bind = computed<any>(() => ({
icon: icon.value,
mode: props.mode,
inline: props.inline,
rotate: props.rotate,
flip: props.flip,
vFlip: props.vFlip,
hFlip: props.hFlip,
color: props.color,
width: size.value,
height: size.value,
style: props.style,
}))
</script>
<script lang="ts">
declare const __VP_ICONIFY_SIZE__: string
declare const __VP_ICONIFY_COLOR__: string
</script>
<template>
<ClientOnly>
<span v-if="!loaded" class="vp-iconify" :style="{ color, width: size, height: size }" />
<OfflineIcon
v-else-if="icon"
class="vp-iconify"
v-bind="bind"
/>
</ClientOnly>
</template>
<style scoped>
.vp-iconify {
display: inline-block;
vertical-align: middle;
}
</style>

View File

@ -1,32 +0,0 @@
import type { IconifyIcon } from '@iconify/vue'
import { loadIcon } from '@iconify/vue'
import { ref, watch } from 'vue'
import type { Ref } from 'vue'
export function useIconify(name: Ref<string>) {
const icon = ref<IconifyIcon | null>(null)
const loaded = ref(false)
async function loadIconComponent() {
if (icon.value)
return
if (!__VUEPRESS_SSR__) {
try {
loaded.value = false
const cached = await loadIcon(name.value)
icon.value = cached
}
finally {
loaded.value = true
}
}
else {
loaded.value = true
}
}
watch(() => name.value, loadIconComponent, { immediate: true })
return { icon, loaded }
}

View File

@ -1 +0,0 @@
export * from './iconify.js'

View File

@ -1,11 +0,0 @@
import { defineClientConfig } from 'vuepress/client'
import type { ClientConfig } from 'vuepress/client'
import Iconify from './components/Iconify.vue'
declare const __VP_ICONIFY_NAME__: string
export default defineClientConfig({
enhance({ app }) {
const name = __VP_ICONIFY_NAME__ || 'Iconify'
app.component(name, Iconify)
},
}) as ClientConfig

View File

@ -1,6 +0,0 @@
import { iconifyPlugin } from './plugin.js'
export * from './plugin.js'
/** @deprecated 请使用 具名导出 替代 默认导出 */
export default iconifyPlugin

View File

@ -1,24 +0,0 @@
import type { Plugin } from 'vuepress/core'
import { getDirname, path } from 'vuepress/utils'
export interface IconifyPluginOptions {
componentName?: string
color?: string
size?: string | number
}
export function iconifyPlugin({
componentName = 'Iconify',
size = '1em',
color = 'currentColor',
}: IconifyPluginOptions = {}): Plugin {
return {
name: '@vuepress-plume/plugin-iconify',
define: {
__VP_ICONIFY_NAME__: componentName,
__VP_ICONIFY_SIZE__: size,
__VP_ICONIFY_COLOR__: color,
},
clientConfigFile: path.resolve(getDirname(import.meta.url), '../client/config.js'),
}
}

View File

@ -1,6 +0,0 @@
declare module '*.vue' {
const comp: any
export default comp
}
declare const __VUEPRESS_SSR__: boolean

View File

@ -1,38 +0,0 @@
import { type Options, defineConfig } from 'tsup'
const clientExternal: (string | RegExp)[] = [
/.*\.vue$/,
/.*\.css$/,
]
export default defineConfig(() => {
const DEFAULT_OPTIONS: Options = {
dts: true,
sourcemap: false,
splitting: false,
format: 'esm',
}
return [
// node
{
...DEFAULT_OPTIONS,
entry: ['./src/node/index.ts'],
outDir: './lib/node',
target: 'node18',
},
// client/composables/index.js
{
...DEFAULT_OPTIONS,
entry: ['./src/client/composables/index.ts'],
outDir: './lib/client/composables',
external: clientExternal,
},
// client/config.js
{
...DEFAULT_OPTIONS,
entry: ['./src/client/config.ts'],
outDir: './lib/client',
external: clientExternal,
},
]
})

View File

@ -39,12 +39,10 @@ export function resolveOptions(
}
const notesList = resolveNotesOptions(localeOptions)
const localesNotesDirs = notesList
.flatMap(({ notes, dir }) => {
dir = removeLeadingSlash(dir || '')
return notes.map(note => normalizePath(`${dir}/${note.dir || ''}/`))
})
.filter(Boolean)
const localesNotesDirs = uniq(notesList
.flatMap(({ notes, dir }) =>
notes.map(note => removeLeadingSlash(normalizePath(`${dir}/${note.dir || ''}/`))),
))
const baseFrontmatter: AutoFrontmatterObject = {}