From 4735ca7b97becdb4c8251fca5fea3fb3f1721826 Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Mon, 24 Feb 2025 08:56:10 +0800 Subject: [PATCH] feat: remove `plugin-content-update`, instead vuepress built-in api --- plugins/plugin-content-update/LICENSE | 21 ------- plugins/plugin-content-update/README.md | 29 --------- plugins/plugin-content-update/package.json | 54 ---------------- .../src/client/components/Content.ts | 35 ----------- .../src/client/composables/index.ts | 24 ------- .../src/client/config.ts | 12 ---- .../plugin-content-update/src/client/index.ts | 2 - .../plugin-content-update/src/node/index.ts | 5 -- .../plugin-content-update/src/node/plugin.ts | 11 ---- plugins/plugin-content-update/tsup.config.ts | 62 ------------------- theme/src/client/composables/outline.ts | 3 +- theme/src/node/plugins/getPlugins.ts | 2 - 12 files changed, 1 insertion(+), 259 deletions(-) delete mode 100644 plugins/plugin-content-update/LICENSE delete mode 100644 plugins/plugin-content-update/README.md delete mode 100644 plugins/plugin-content-update/package.json delete mode 100644 plugins/plugin-content-update/src/client/components/Content.ts delete mode 100644 plugins/plugin-content-update/src/client/composables/index.ts delete mode 100644 plugins/plugin-content-update/src/client/config.ts delete mode 100644 plugins/plugin-content-update/src/client/index.ts delete mode 100644 plugins/plugin-content-update/src/node/index.ts delete mode 100644 plugins/plugin-content-update/src/node/plugin.ts delete mode 100644 plugins/plugin-content-update/tsup.config.ts diff --git a/plugins/plugin-content-update/LICENSE b/plugins/plugin-content-update/LICENSE deleted file mode 100644 index 9f677c90..00000000 --- a/plugins/plugin-content-update/LICENSE +++ /dev/null @@ -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. diff --git a/plugins/plugin-content-update/README.md b/plugins/plugin-content-update/README.md deleted file mode 100644 index e9033ada..00000000 --- a/plugins/plugin-content-update/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# `@vuepress-plume/plugin-content-update` - -替换 `@vuepress/client` 的 `` 组件,注入 `onContentUpdated` 生命周期。 -实现当页面内容发生更新时,触发 `onContentUpdated` 事件。 - -## Install - -```sh -npm install @vuepress-plume/plugin-content-update -# or -pnpm add @vuepress-plume/plugin-content-update -# or -yarn add @vuepress-plume/plugin-content-update -``` - -## Usage - -``` js -// .vuepress/config.[jt]s -import { contentUpdatePlugin } from '@vuepress-plume/plugin-content-update' - -export default { - // ... - plugins: [ - contentUpdatePlugin() - ] - // ... -} -``` diff --git a/plugins/plugin-content-update/package.json b/plugins/plugin-content-update/package.json deleted file mode 100644 index 4158ff4f..00000000 --- a/plugins/plugin-content-update/package.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "name": "@vuepress-plume/plugin-content-update", - "type": "module", - "version": "1.0.0-rc.131", - "description": "The Plugin for VuePress 2 - content update", - "author": "pengzhanbo ", - "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-content-update" - }, - "bugs": { - "url": "https://github.com/pengzhanbo/vuepress-theme-plume/issues" - }, - "exports": { - ".": { - "types": "./lib/node/index.d.ts", - "import": "./lib/node/index.js" - }, - "./client": { - "types": "./lib/client/index.d.ts", - "import": "./lib/client/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": "catalog:" - }, - "dependencies": { - "vue": "catalog:" - }, - "publishConfig": { - "access": "public" - }, - "keyword": [ - "VuePress", - "vuepress plugin", - "content-update", - "vuepress-plugin-content-update" - ] -} diff --git a/plugins/plugin-content-update/src/client/components/Content.ts b/plugins/plugin-content-update/src/client/components/Content.ts deleted file mode 100644 index 4ccfc038..00000000 --- a/plugins/plugin-content-update/src/client/components/Content.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { computed, defineAsyncComponent, defineComponent, h } from 'vue' -import { resolveRoute, usePageComponent } from 'vuepress/client' -import { runCallbacks } from '../composables/index.js' - -/** - * Markdown rendered content - */ -export const Content = defineComponent({ - - name: 'Content', - - props: { - path: { - type: String, - required: false, - default: '', - }, - }, - - setup(props) { - const pageComponent = usePageComponent() - const ContentComponent = computed(() => { - if (!props.path) - return pageComponent.value - const route = resolveRoute(props.path) - return defineAsyncComponent(() => route.loader().then(({ comp }) => comp as any)) - }) - - return () => h(ContentComponent.value, { - onVnodeMounted: () => runCallbacks({ mounted: true }), - onVnodeUpdated: () => runCallbacks({ updated: true }), - onVnodeBeforeUnmount: () => runCallbacks({ beforeUnmount: true }), - }) - }, -}) diff --git a/plugins/plugin-content-update/src/client/composables/index.ts b/plugins/plugin-content-update/src/client/composables/index.ts deleted file mode 100644 index 64bff3b1..00000000 --- a/plugins/plugin-content-update/src/client/composables/index.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { onUnmounted } from 'vue' - -export interface ContentUpdated { - mounted?: boolean - updated?: boolean - beforeUnmount?: boolean -} - -let contentUpdatedCallbacks: ((lifeCircleType: ContentUpdated) => any)[] = [] - -/** - * Register callback that is called every time the markdown content is updated - * in the DOM. - */ -export function onContentUpdated(fn: () => any) { - contentUpdatedCallbacks.push(fn) - onUnmounted(() => { - contentUpdatedCallbacks = contentUpdatedCallbacks.filter(f => f !== fn) - }) -} - -export function runCallbacks(lifeCircleType: ContentUpdated) { - contentUpdatedCallbacks.forEach(fn => fn(lifeCircleType)) -} diff --git a/plugins/plugin-content-update/src/client/config.ts b/plugins/plugin-content-update/src/client/config.ts deleted file mode 100644 index 0e879a26..00000000 --- a/plugins/plugin-content-update/src/client/config.ts +++ /dev/null @@ -1,12 +0,0 @@ -import type { ClientConfig } from 'vuepress/client' -import { defineClientConfig } from 'vuepress/client' -import { Content } from './components/Content.js' - -export default defineClientConfig({ - enhance({ app }) { - if (app._context.components.Content) - delete app._context.components.Content - - app.component('Content', Content) - }, -}) as ClientConfig diff --git a/plugins/plugin-content-update/src/client/index.ts b/plugins/plugin-content-update/src/client/index.ts deleted file mode 100644 index 5a4bbf87..00000000 --- a/plugins/plugin-content-update/src/client/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './components/Content.js' -export { onContentUpdated } from './composables/index.js' diff --git a/plugins/plugin-content-update/src/node/index.ts b/plugins/plugin-content-update/src/node/index.ts deleted file mode 100644 index 429a98f1..00000000 --- a/plugins/plugin-content-update/src/node/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { contentUpdatePlugin } from './plugin.js' - -export { contentUpdatePlugin } - -export default contentUpdatePlugin diff --git a/plugins/plugin-content-update/src/node/plugin.ts b/plugins/plugin-content-update/src/node/plugin.ts deleted file mode 100644 index cff5534a..00000000 --- a/plugins/plugin-content-update/src/node/plugin.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type { Plugin } from 'vuepress/core' -import { getDirname, path } from 'vuepress/utils' - -const __dirname = getDirname(import.meta.url) - -export function contentUpdatePlugin(): Plugin { - return { - name: '@vuepress-plume/plugin-content-update', - clientConfigFile: path.resolve(__dirname, '../client/config.js'), - } -} diff --git a/plugins/plugin-content-update/tsup.config.ts b/plugins/plugin-content-update/tsup.config.ts deleted file mode 100644 index 38b0a505..00000000 --- a/plugins/plugin-content-update/tsup.config.ts +++ /dev/null @@ -1,62 +0,0 @@ -import type { Options } from 'tsup' -import { defineConfig } from 'tsup' -import { argv } from '../../scripts/tsup-args.js' - -const clientExternal: (string | RegExp)[] = [ - /.*\.vue$/, - /.*\.css$/, -] - -export default defineConfig(() => { - const DEFAULT_OPTIONS: Options = { - dts: true, - sourcemap: false, - splitting: false, - format: 'esm', - } - - const options: Options[] = [] - - if (argv.node) { - options.push({ - ...DEFAULT_OPTIONS, - entry: ['./src/node/index.ts'], - outDir: './lib/node', - target: 'node18', - }) - } - if (argv.client) { - options.push(...[ - // client/composables/index.js - { - ...DEFAULT_OPTIONS, - entry: ['./src/client/composables/index.ts'], - outDir: './lib/client/composables', - external: clientExternal, - }, - // client/components/index.js - { - ...DEFAULT_OPTIONS, - entry: ['./src/client/components/Content.ts'], - outDir: './lib/client/components', - external: [...clientExternal, '../composables/index.js'], - }, - // client/config.js - { - ...DEFAULT_OPTIONS, - entry: ['./src/client/config.ts'], - outDir: './lib/client', - dts: false, - external: [...clientExternal, './components/Content.js'], - }, - // client/index.js - { - ...DEFAULT_OPTIONS, - entry: ['./src/client/index.ts'], - outDir: './lib/client', - external: [...clientExternal, './components/Content.js', './composables/index.js'], - }, - ]) - } - return options -}) diff --git a/theme/src/client/composables/outline.ts b/theme/src/client/composables/outline.ts index 1bcd509a..b0366965 100644 --- a/theme/src/client/composables/outline.ts +++ b/theme/src/client/composables/outline.ts @@ -1,10 +1,9 @@ import type { InjectionKey, Ref } from 'vue' import type { Router } from 'vuepress/client' import type { ThemeOutline } from '../../shared/index.js' -import { onContentUpdated } from '@vuepress-plume/plugin-content-update/client' import { useThrottleFn, watchDebounced } from '@vueuse/core' import { inject, onMounted, onUnmounted, onUpdated, provide, ref } from 'vue' -import { useRouter } from 'vuepress/client' +import { onContentUpdated, useRouter } from 'vuepress/client' import { useAside } from './aside.js' import { useData } from './data.js' diff --git a/theme/src/node/plugins/getPlugins.ts b/theme/src/node/plugins/getPlugins.ts index 460999e7..99a1b98d 100644 --- a/theme/src/node/plugins/getPlugins.ts +++ b/theme/src/node/plugins/getPlugins.ts @@ -2,7 +2,6 @@ import type { SeoPluginOptions } from '@vuepress/plugin-seo' import type { SitemapPluginOptions } from '@vuepress/plugin-sitemap' import type { App, PluginConfig } from 'vuepress/core' import type { PlumeThemePluginOptions } from '../../shared/index.js' -import { contentUpdatePlugin } from '@vuepress-plume/plugin-content-update' import { fontsPlugin } from '@vuepress-plume/plugin-fonts' import { searchPlugin } from '@vuepress-plume/plugin-search' import { shikiPlugin } from '@vuepress-plume/plugin-shikiji' @@ -43,7 +42,6 @@ export function getPlugins({ const plugins: PluginConfig = [ fontsPlugin(), - contentUpdatePlugin(), markdownHintPlugin({ hint: true, alert: true, injectStyles: false }), ]