Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RC-7 #30

Merged
merged 9 commits into from
Dec 28, 2023
Merged

RC-7 #30

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "module",
"version": "1.0.0-rc.6",
"private": true,
"packageManager": "pnpm@8.12.1",
"packageManager": "pnpm@8.13.1",
"author": "pengzhanbo",
"license": "MIT",
"keywords": [
Expand All @@ -18,7 +18,6 @@
"pnpm": ">=7"
},
"scripts": {
"autoUpdate": "node scripts/autoInstall.js",
"build": "pnpm run build:package",
"build:package": "pnpm --filter=!vuepress-theme-plume-monorepo --filter=!docs run -r --stream build",
"commit": "cz",
Expand All @@ -36,8 +35,7 @@
"release:changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"release:check": "pnpm lint && pnpm build",
"release:publish": "pnpm -r publish",
"release:version": "bumpp package.json plugins/*/package.json theme/package.json --execute=\"pnpm release:changelog\" --commit \"build: publish v%s\" --all --tag --push",
"up": "taze -r major"
"release:version": "bumpp package.json plugins/*/package.json theme/package.json --execute=\"pnpm release:changelog\" --commit \"build: publish v%s\" --all --tag --push"
},
"devDependencies": {
"@commitlint/cli": "^18.4.3",
Expand All @@ -62,10 +60,10 @@
"lint-staged": "^15.2.0",
"minimist": "^1.2.8",
"ora": "^8.0.1",
"pnpm": "^8.12.1",
"pnpm": "^8.13.1",
"rimraf": "^5.0.5",
"sort-package-json": "^2.6.0",
"taze": "^0.13.0",
"taze": "^0.13.1",
"tsconfig-vuepress": "^4.5.0",
"typescript": "^5.3.3",
"vite": "^5.0.10"
Expand Down
21 changes: 21 additions & 0 deletions plugins/plugin-content-update/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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.
21 changes: 21 additions & 0 deletions plugins/plugin-content-update/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# `@vuepress-plume/plugin-content-update`

替换 `@vuepress/client` 的 `<Content />` 组件,注入 `onContentUpdated` 生命周期。
实现当页面内容发生更新时,触发 `onContentUpdated` 事件。

## Install
```
yarn add @vuepress-plume/plugin-content-update
```
## Usage
``` js
// .vuepress/config.js
const { contentUpdatePlugin } = require('@vuepress-plume/plugin-content-update')
module.exports = {
// ...
plugins: [
contentUpdatePlugin()
]
// ...
}
```
49 changes: 49 additions & 0 deletions plugins/plugin-content-update/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@vuepress-plume/plugin-content-update",
"type": "module",
"version": "1.0.0-rc.6",
"description": "The Plugin for VuePres 2",
"author": "pengzhanbo <[email protected]>",
"license": "MIT",
"homepage": "https://github.com/pengzhanbo/vuepress-theme-plume#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/pengzhanbo/vuepress-theme-plume.git"
},
"bugs": {
"url": "https://github.com/pengzhanbo/vuepress-theme-plume/issues"
},
"exports": {
".": "./lib/node/index.js",
"./client": "./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 clean && pnpm run copy && pnpm run ts",
"clean": "rimraf lib *.tsbuildinfo",
"copy": "cpx \"src/**/*.{d.ts,vue,css,scss,jpg,png}\" lib",
"ts": "tsc -b tsconfig.build.json"
},
"dependencies": {
"@vuepress/client": "2.0.0-rc.0",
"@vuepress/core": "2.0.0-rc.0",
"@vuepress/shared": "2.0.0-rc.0",
"@vuepress/utils": "2.0.0-rc.0",
"vue": "^3.3.13",
"vue-router": "4.2.5"
},
"publishConfig": {
"access": "public"
},
"keyword": [
"VuePress",
"vuepress plugin",
"content-update",
"vuepress-plugin-plugin-content-update"
]
}
11 changes: 11 additions & 0 deletions plugins/plugin-content-update/src/client/clientConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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)
},
})
42 changes: 42 additions & 0 deletions plugins/plugin-content-update/src/client/components/Content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { pagesComponents } from '@internal/pagesComponents'
import { computed, defineComponent, h } from 'vue'
import { usePageData } from '@vuepress/client'
import { runCallbacks } from '../composables/index.js'

declare const __VUEPRESS_DEV__: boolean

/**
* Markdown rendered content
*/
export const Content = defineComponent({

name: 'Content',

props: {
pageKey: {
type: String,
required: false,
default: '',
},
},

setup(props) {
const page = usePageData()
const pageComponent = computed(
() => pagesComponents[props.pageKey || page.value.key],
)
return () =>
pageComponent.value
? h(pageComponent.value, {
onVnodeMounted: runCallbacks,
onVnodeUpdated: runCallbacks,
onVnodeBeforeUnmount: runCallbacks,
})
: h(
'div',
__VUEPRESS_DEV__
? 'Page does not exist. This is a fallback content.'
: '404 Not Found',
)
},
})
19 changes: 19 additions & 0 deletions plugins/plugin-content-update/src/client/composables/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { onUnmounted } from 'vue'

// eslint-disable-next-line import/no-mutable-exports
export let contentUpdatedCallbacks: (() => 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() {
contentUpdatedCallbacks.forEach(fn => fn())
}
2 changes: 2 additions & 0 deletions plugins/plugin-content-update/src/client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './components/Content.js'
export { onContentUpdated } from './composables/index.js'
5 changes: 5 additions & 0 deletions plugins/plugin-content-update/src/node/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { contentUpdatePlugin } from './plugin.js'

export { contentUpdatePlugin }

export default contentUpdatePlugin
11 changes: 11 additions & 0 deletions plugins/plugin-content-update/src/node/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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/clientConfig.js'),
}
}
4 changes: 4 additions & 0 deletions plugins/plugin-content-update/src/shim.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '@internal/pagesComponents' {
const pagesComponents: Record<string, any>
export { pagesComponents }
}
8 changes: 8 additions & 0 deletions plugins/plugin-content-update/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.build.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./lib"
},
"include": ["./src"]
}
4 changes: 2 additions & 2 deletions plugins/plugin-copy-code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
"ts": "tsc -b tsconfig.build.json"
},
"dependencies": {
"@vuepress-plume/plugin-content-update": "workspace:*",
"@vuepress/client": "2.0.0-rc.0",
"@vuepress/core": "2.0.0-rc.0",
"@vuepress/shared": "2.0.0-rc.0",
"@vuepress/utils": "2.0.0-rc.0",
"vue": "^3.3.13",
"vue-router": "4.2.5"
"vue": "^3.3.13"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugin-copy-code/src/client/clientConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineClientConfig } from '@vuepress/client'
import { setupCopyCode } from './composables/index.js'
import { setupCopyCode } from './setupCopyCode.js'

import './styles/button.scss'

Expand Down
23 changes: 0 additions & 23 deletions plugins/plugin-copy-code/src/client/composables/copyToClipboard.ts

This file was deleted.

1 change: 0 additions & 1 deletion plugins/plugin-copy-code/src/client/composables/index.ts

This file was deleted.

67 changes: 0 additions & 67 deletions plugins/plugin-copy-code/src/client/composables/setup.ts

This file was deleted.

Loading