feat: remove plugin-content-update, instead vuepress built-in api
This commit is contained in:
parent
2d24a61d7d
commit
4735ca7b97
@ -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.
|
||||
@ -1,29 +0,0 @@
|
||||
# `@vuepress-plume/plugin-content-update`
|
||||
|
||||
替换 `@vuepress/client` 的 `<Content />` 组件,注入 `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()
|
||||
]
|
||||
// ...
|
||||
}
|
||||
```
|
||||
@ -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 <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-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"
|
||||
]
|
||||
}
|
||||
@ -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 }),
|
||||
})
|
||||
},
|
||||
})
|
||||
@ -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))
|
||||
}
|
||||
@ -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
|
||||
@ -1,2 +0,0 @@
|
||||
export * from './components/Content.js'
|
||||
export { onContentUpdated } from './composables/index.js'
|
||||
@ -1,5 +0,0 @@
|
||||
import { contentUpdatePlugin } from './plugin.js'
|
||||
|
||||
export { contentUpdatePlugin }
|
||||
|
||||
export default contentUpdatePlugin
|
||||
@ -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'),
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
})
|
||||
@ -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'
|
||||
|
||||
|
||||
@ -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 }),
|
||||
]
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user