From 3f582af7188bb742a410a386a7033de8a5d45b71 Mon Sep 17 00:00:00 2001 From: reco_luan Date: Thu, 25 Apr 2024 03:04:50 +0800 Subject: [PATCH] refactor: optimize code --- .../src/client/clientSetup.ts | 22 +++++---- .../src/client/components/Common/hook.ts | 2 +- .../src/client/components/Common/index.vue | 5 +- .../src/client/components/FriendshipLink.vue | 2 +- .../src/client/components/Home/Banner.vue | 14 +----- .../client/components/Home/BannerBrand.vue | 15 ++---- .../src/client/components/Home/Footer.vue | 6 +-- .../src/client/components/Home/index.vue | 6 +-- .../src/client/components/Link.vue | 10 ++-- .../src/client/components/Navbar.vue | 11 +++-- .../src/client/components/NavbarLinks.vue | 40 +++++++++------ .../src/client/components/Page/hook.ts | 2 +- .../src/client/components/PageMeta.vue | 36 +++++--------- .../src/client/components/PageNav.vue | 5 +- .../client/components/PagePassword/hook.ts | 2 +- .../src/client/components/Password/hook.ts | 2 +- .../src/client/components/PersonalInfo.vue | 28 +++++------ .../src/client/components/Series.vue | 18 +++++-- .../src/client/composables/index.ts | 17 ++++--- .../src/client/composables/usePageData.ts | 13 +++++ .../src/client/composables/useSeriesData.ts | 2 +- .../src/client/layouts/Layout.vue | 15 +++--- .../src/client/layouts/NotFound.vue | 4 +- .../vuepress-theme-reco/src/node/recoTheme.ts | 20 ++++---- .../src/node/resolvePlugins.ts | 4 +- .../vuepress-theme-reco/src/types/models.d.ts | 2 +- .../vuepress-theme-reco/src/types/options.ts | 49 ++++++++++++++++++- .../vuepress-theme-reco/src/types/page.ts | 29 ++++++++--- .../vuepress-theme-reco/tsconfig.build.json | 7 ++- 29 files changed, 229 insertions(+), 159 deletions(-) create mode 100644 packages/vuepress-theme-reco/src/client/composables/usePageData.ts diff --git a/packages/vuepress-theme-reco/src/client/clientSetup.ts b/packages/vuepress-theme-reco/src/client/clientSetup.ts index 4d00d413..d3ad85a8 100644 --- a/packages/vuepress-theme-reco/src/client/clientSetup.ts +++ b/packages/vuepress-theme-reco/src/client/clientSetup.ts @@ -1,13 +1,15 @@ import { computed, provide } from 'vue' -import { usePageFrontmatter, useRoute, usePageData } from 'vuepress/client' -import { useExtendPageData } from '@vuepress-reco/vuepress-plugin-page/lib/client/composable/index.js' +import { useRoute } from 'vuepress/client' import { - resolveSeriesItems, - seriesItemsSymbol, - headersToCatalog, + usePageData, catalogSymbol, + headersToCatalog, + seriesItemsSymbol, + resolveSeriesItems, useThemeLocaleData, -} from './composables/index.js' + usePageFrontmatter, +} from '@composables/index.js' +import { useExtendPageData } from '@vuepress-reco/vuepress-plugin-page/lib/client/composable/index.js' import type { RecoThemeNormalPageFrontmatter } from '../types' @@ -15,10 +17,12 @@ export function applyClientSetup() { // we need to access series items in multiple components // so we make it global computed const themeLocal = useThemeLocaleData() - const frontmatter = usePageFrontmatter() - const route = useRoute() + const frontmatter = usePageFrontmatter() + const route = useRoute() const { series } = useExtendPageData() - const seriesItems = computed(() => resolveSeriesItems(frontmatter.value, themeLocal.value, route, series)) + const seriesItems = computed(() => + resolveSeriesItems(frontmatter.value, themeLocal.value, route, series) + ) provide(seriesItemsSymbol, seriesItems) const page = usePageData() diff --git a/packages/vuepress-theme-reco/src/client/components/Common/hook.ts b/packages/vuepress-theme-reco/src/client/components/Common/hook.ts index 88093029..8900686c 100644 --- a/packages/vuepress-theme-reco/src/client/components/Common/hook.ts +++ b/packages/vuepress-theme-reco/src/client/components/Common/hook.ts @@ -1,7 +1,7 @@ import { useRouter, useRoute } from 'vue-router' import { watch, ref, onMounted, onUnmounted, toRefs } from 'vue' +import { useScrollDirection, useThemeLocaleData } from '@composables/index.js' import { useInitCopyBtn } from '@vuepress-reco/vuepress-plugin-code-copy/lib/client/composables/initCopyBtn.js' -import { useScrollDirection, useThemeLocaleData } from '../../composables/index.js' export function useSeries(toggleSeries, toggleMobileMenus) { // close series after navigation diff --git a/packages/vuepress-theme-reco/src/client/components/Common/index.vue b/packages/vuepress-theme-reco/src/client/components/Common/index.vue index 7326656a..e5af7631 100644 --- a/packages/vuepress-theme-reco/src/client/components/Common/index.vue +++ b/packages/vuepress-theme-reco/src/client/components/Common/index.vue @@ -31,7 +31,6 @@ diff --git a/packages/vuepress-theme-reco/src/client/components/Link.vue b/packages/vuepress-theme-reco/src/client/components/Link.vue index b15c9fe3..2cbb5f31 100644 --- a/packages/vuepress-theme-reco/src/client/components/Link.vue +++ b/packages/vuepress-theme-reco/src/client/components/Link.vue @@ -31,13 +31,15 @@ diff --git a/packages/vuepress-theme-reco/src/client/components/Series.vue b/packages/vuepress-theme-reco/src/client/components/Series.vue index 502ca6a1..53836308 100644 --- a/packages/vuepress-theme-reco/src/client/components/Series.vue +++ b/packages/vuepress-theme-reco/src/client/components/Series.vue @@ -1,16 +1,24 @@