From 6c9377eb2dfc7a267a098ac2b8c85af1620a3bfb Mon Sep 17 00:00:00 2001 From: reco_luan Date: Wed, 22 Nov 2023 22:24:31 +0800 Subject: [PATCH] fix: fix error about plugin-theme-data --- .../plugin-bulletin-popover/package.json | 6 ++++-- .../src/client/components/hook.ts | 19 ++++++++++++++++++- .../src/types/models.d.ts | 1 + .../src/types/shim.d.ts | 2 -- .../plugin-comments/package.json | 1 + .../src/client/components/ValineViews.ts | 12 ++---------- .../src/client/composables/index.ts | 19 ++++++++++++++++++- .../plugin-comments/src/types/shim.d.ts | 7 +++++++ packages/@vuepress-reco/shared/package.json | 5 ++++- .../@vuepress-reco/shared/src/types/shim.d.ts | 2 ++ .../vuepress-theme-reco/src/node/recoTheme.ts | 2 +- pnpm-lock.yaml | 14 +++++++++++++- 12 files changed, 71 insertions(+), 19 deletions(-) create mode 100644 packages/@vuepress-reco/plugin-bulletin-popover/src/types/models.d.ts create mode 100644 packages/@vuepress-reco/plugin-comments/src/types/shim.d.ts diff --git a/packages/@vuepress-reco/plugin-bulletin-popover/package.json b/packages/@vuepress-reco/plugin-bulletin-popover/package.json index 23ab551d..59d93253 100644 --- a/packages/@vuepress-reco/plugin-bulletin-popover/package.json +++ b/packages/@vuepress-reco/plugin-bulletin-popover/package.json @@ -36,11 +36,13 @@ "access": "public" }, "dependencies": { - "@vuepress-reco/tailwindcss-config": "workspace:2.0.0-beta.68", + "@vuepress-reco/tailwindcss-config": "workspace:*", "@vuepress/client": "2.0.0-rc.0", "@vuepress/core": "2.0.0-rc.0", "@vuepress/plugin-theme-data": "2.0.0-rc.0", + "@vuepress/shared": "2.0.0-rc.0", "@vuepress/utils": "2.0.0-rc.0", - "vue": "^3.3.8" + "vue": "^3.3.8", + "vue-router": "^4.2.5" } } diff --git a/packages/@vuepress-reco/plugin-bulletin-popover/src/client/components/hook.ts b/packages/@vuepress-reco/plugin-bulletin-popover/src/client/components/hook.ts index 1b6f8d9b..29e93d69 100644 --- a/packages/@vuepress-reco/plugin-bulletin-popover/src/client/components/hook.ts +++ b/packages/@vuepress-reco/plugin-bulletin-popover/src/client/components/hook.ts @@ -1,5 +1,7 @@ import { ref, onMounted, computed } from 'vue' -import { useThemeLocaleData } from '@vuepress/plugin-theme-data/client' +import { useRouter } from 'vue-router' +import { resolveLocalePath } from '@vuepress/shared' +import { useThemeData, resolveThemeLocaleData } from '@vuepress/plugin-theme-data/client' export function useVisible() { const themeLocal = useThemeLocaleData() @@ -66,3 +68,18 @@ export function useHandleNodes() { return { bodyNodes, handleNode } } + +function useThemeLocaleData() { + const themeData = useThemeData() + const router = useRouter() + const routePath = computed(() => router.currentRoute.value.path) + const routeLocale = computed(() => + resolveLocalePath(themeData.value.locales, routePath.value), + ) + + const themeLocaleData = computed(() => + resolveThemeLocaleData(themeData.value, routeLocale.value), + ) + + return themeLocaleData +} diff --git a/packages/@vuepress-reco/plugin-bulletin-popover/src/types/models.d.ts b/packages/@vuepress-reco/plugin-bulletin-popover/src/types/models.d.ts new file mode 100644 index 00000000..6658a066 --- /dev/null +++ b/packages/@vuepress-reco/plugin-bulletin-popover/src/types/models.d.ts @@ -0,0 +1 @@ +declare module '@vuepress/plugin-theme-data/client' diff --git a/packages/@vuepress-reco/plugin-bulletin-popover/src/types/shim.d.ts b/packages/@vuepress-reco/plugin-bulletin-popover/src/types/shim.d.ts index 45191c69..bf554924 100644 --- a/packages/@vuepress-reco/plugin-bulletin-popover/src/types/shim.d.ts +++ b/packages/@vuepress-reco/plugin-bulletin-popover/src/types/shim.d.ts @@ -3,5 +3,3 @@ declare module '*.vue' { const comp: ComponentOptions export default comp } - -declare module '@vuepress/plugin-theme-data/client' diff --git a/packages/@vuepress-reco/plugin-comments/package.json b/packages/@vuepress-reco/plugin-comments/package.json index 396b5fd3..546773c4 100644 --- a/packages/@vuepress-reco/plugin-comments/package.json +++ b/packages/@vuepress-reco/plugin-comments/package.json @@ -39,6 +39,7 @@ "@vuepress/client": "2.0.0-rc.0", "@vuepress/core": "2.0.0-rc.0", "@vuepress/plugin-theme-data": "2.0.0-rc.0", + "@vuepress/shared": "2.0.0-rc.0", "@vuepress/utils": "2.0.0-rc.0", "@waline/client": "^2.14.7", "valine": "1.4.18", diff --git a/packages/@vuepress-reco/plugin-comments/src/client/components/ValineViews.ts b/packages/@vuepress-reco/plugin-comments/src/client/components/ValineViews.ts index 8c8eb1f6..1052952f 100644 --- a/packages/@vuepress-reco/plugin-comments/src/client/components/ValineViews.ts +++ b/packages/@vuepress-reco/plugin-comments/src/client/components/ValineViews.ts @@ -1,5 +1,4 @@ -import { defineComponent, toRefs, h, watch } from 'vue' -import { useSiteLocaleData } from '@vuepress/client' +import { defineComponent, toRefs, h } from 'vue' import { useRoute } from 'vue-router' export default defineComponent({ @@ -18,21 +17,14 @@ export default defineComponent({ }, setup(props) { - const siteLocal = useSiteLocaleData() const route = useRoute() const { idVal, numStyle, flagTitle } = toRefs(props) - const getIdVal = (path) => { - return ( - siteLocal.value.base.slice(0, siteLocal.value.base.length - 1) + path - ) - } - return () => h( 'span', { - 'id': getIdVal(idVal.value || route.path), + 'id': idVal.value || route.path, 'class': 'leancloud-visitors', 'data-flag-title': flagTitle.value, }, diff --git a/packages/@vuepress-reco/plugin-comments/src/client/composables/index.ts b/packages/@vuepress-reco/plugin-comments/src/client/composables/index.ts index deb44d6a..64d1bcf7 100644 --- a/packages/@vuepress-reco/plugin-comments/src/client/composables/index.ts +++ b/packages/@vuepress-reco/plugin-comments/src/client/composables/index.ts @@ -1,5 +1,7 @@ import { computed } from 'vue' -import { useThemeLocaleData } from '@vuepress/plugin-theme-data/client' +import { useRouter } from 'vue-router' +import { resolveLocalePath } from '@vuepress/shared' +import { useThemeData, resolveThemeLocaleData } from '@vuepress/plugin-theme-data/client' export function useComment() { const themeLocal = useThemeLocaleData() @@ -25,3 +27,18 @@ export function useComment() { return { solution, options } } + +function useThemeLocaleData() { + const themeData = useThemeData() + const router = useRouter() + const routePath = computed(() => router.currentRoute.value.path) + const routeLocale = computed(() => + resolveLocalePath(themeData.value.locales, routePath.value), + ) + + const themeLocaleData = computed(() => + resolveThemeLocaleData(themeData.value, routeLocale.value), + ) + + return themeLocaleData +} diff --git a/packages/@vuepress-reco/plugin-comments/src/types/shim.d.ts b/packages/@vuepress-reco/plugin-comments/src/types/shim.d.ts new file mode 100644 index 00000000..1760fde7 --- /dev/null +++ b/packages/@vuepress-reco/plugin-comments/src/types/shim.d.ts @@ -0,0 +1,7 @@ +declare module '*.vue' { + import type { ComponentOptions } from 'vue' + const comp: ComponentOptions + export default comp +} + +declare module '@vuepress-reco/shared' diff --git a/packages/@vuepress-reco/shared/package.json b/packages/@vuepress-reco/shared/package.json index d414ddc4..9b7b6c16 100644 --- a/packages/@vuepress-reco/shared/package.json +++ b/packages/@vuepress-reco/shared/package.json @@ -31,7 +31,10 @@ }, "dependencies": { "@vuepress/core": "2.0.0-rc.0", - "vue": "^3.3.8" + "@vuepress/shared": "2.0.0-rc.0", + "@vuepress/plugin-theme-data": "2.0.0-rc.0", + "vue": "^3.3.8", + "vue-router": "^4.2.5" }, "publishConfig": { "access": "public" diff --git a/packages/@vuepress-reco/shared/src/types/shim.d.ts b/packages/@vuepress-reco/shared/src/types/shim.d.ts index bf554924..45191c69 100644 --- a/packages/@vuepress-reco/shared/src/types/shim.d.ts +++ b/packages/@vuepress-reco/shared/src/types/shim.d.ts @@ -3,3 +3,5 @@ declare module '*.vue' { const comp: ComponentOptions export default comp } + +declare module '@vuepress/plugin-theme-data/client' diff --git a/packages/vuepress-theme-reco/src/node/recoTheme.ts b/packages/vuepress-theme-reco/src/node/recoTheme.ts index 9125143c..166716b2 100644 --- a/packages/vuepress-theme-reco/src/node/recoTheme.ts +++ b/packages/vuepress-theme-reco/src/node/recoTheme.ts @@ -41,11 +41,11 @@ const __dirname = getDirname(import.meta.url) export const recoTheme = (themeConfig: Record): Theme => { const plugins = [ + themeDataPlugin({ themeData: themeConfig }), bulletinPopoverPlugin(), commentsPlugin(), pagePlugin(pages || [], themeConfig), gitPlugin(), - themeDataPlugin({ themeData: themeConfig }), searchPlugin({ hotKeys: [{ key: 's', ctrl: true }], }), diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0eedbbb0..c6c5c49f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -78,19 +78,23 @@ importers: packages/@vuepress-reco/plugin-bulletin-popover: specifiers: - '@vuepress-reco/tailwindcss-config': workspace:2.0.0-beta.68 + '@vuepress-reco/tailwindcss-config': workspace:* '@vuepress/client': 2.0.0-rc.0 '@vuepress/core': 2.0.0-rc.0 '@vuepress/plugin-theme-data': 2.0.0-rc.0 + '@vuepress/shared': 2.0.0-rc.0 '@vuepress/utils': 2.0.0-rc.0 vue: ^3.3.8 + vue-router: ^4.2.5 dependencies: '@vuepress-reco/tailwindcss-config': link:../tailwindcss-config '@vuepress/client': 2.0.0-rc.0 '@vuepress/core': 2.0.0-rc.0 '@vuepress/plugin-theme-data': 2.0.0-rc.0 + '@vuepress/shared': 2.0.0-rc.0 '@vuepress/utils': 2.0.0-rc.0 vue: 3.3.8 + vue-router: 4.2.5_vue@3.3.8 packages/@vuepress-reco/plugin-code-copy: specifiers: @@ -111,6 +115,7 @@ importers: '@vuepress/client': 2.0.0-rc.0 '@vuepress/core': 2.0.0-rc.0 '@vuepress/plugin-theme-data': 2.0.0-rc.0 + '@vuepress/shared': 2.0.0-rc.0 '@vuepress/utils': 2.0.0-rc.0 '@waline/client': ^2.14.7 valine: 1.4.18 @@ -122,6 +127,7 @@ importers: '@vuepress/client': 2.0.0-rc.0 '@vuepress/core': 2.0.0-rc.0 '@vuepress/plugin-theme-data': 2.0.0-rc.0 + '@vuepress/shared': 2.0.0-rc.0 '@vuepress/utils': 2.0.0-rc.0 '@waline/client': 2.15.8 valine: 1.4.18 @@ -181,10 +187,16 @@ importers: packages/@vuepress-reco/shared: specifiers: '@vuepress/core': 2.0.0-rc.0 + '@vuepress/plugin-theme-data': 2.0.0-rc.0 + '@vuepress/shared': 2.0.0-rc.0 vue: ^3.3.8 + vue-router: ^4.2.5 dependencies: '@vuepress/core': 2.0.0-rc.0 + '@vuepress/plugin-theme-data': 2.0.0-rc.0 + '@vuepress/shared': 2.0.0-rc.0 vue: 3.3.8 + vue-router: 4.2.5_vue@3.3.8 packages/@vuepress-reco/tailwindcss-config: specifiers: {}