From 23f13b175d9b988cf0ad468e706205da3ccf39a0 Mon Sep 17 00:00:00 2001 From: Lukas Leisten Date: Tue, 18 Mar 2025 09:46:09 +0100 Subject: [PATCH] feat(themeConfig):Added skip Title update --- docs/en/reference/default-theme-config.md | 7 +++++++ src/client/app/composables/head.ts | 8 +++++--- src/node/alias.ts | 12 +++++------- types/default-theme.d.ts | 5 +++++ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/docs/en/reference/default-theme-config.md b/docs/en/reference/default-theme-config.md index c8afc554..7c42ee8c 100644 --- a/docs/en/reference/default-theme-config.md +++ b/docs/en/reference/default-theme-config.md @@ -451,6 +451,13 @@ Can be used to customize the aria-label of the language toggle button in navbar. Can be used to customize the label of the skip to content link. This link is shown when the user is navigating the site using a keyboard. +## skipTitleUpdate + +- Type: `boolean` +- Default: `false` + +Can be used to skip the default title update logic so it can be implemented on your own. + ## externalLinkIcon - Type: `boolean` diff --git a/src/client/app/composables/head.ts b/src/client/app/composables/head.ts index 13fb9bb0..7a18724d 100644 --- a/src/client/app/composables/head.ts +++ b/src/client/app/composables/head.ts @@ -56,9 +56,11 @@ export function useUpdateHead(route: Route, siteDataByRouteRef: Ref) { const frontmatterHead = (pageData && pageData.frontmatter.head) || [] // update title and description - const title = createTitle(siteData, pageData) - if (title !== document.title) { - document.title = title + if (!siteData.themeConfig.skipTitleUpdate) { + const title = createTitle(siteData, pageData) + if (title !== document.title) { + document.title = title + } } const description = pageDescription || siteData.description diff --git a/src/node/alias.ts b/src/node/alias.ts index 9f2aefaf..ad9eae4b 100644 --- a/src/node/alias.ts +++ b/src/node/alias.ts @@ -44,24 +44,22 @@ export function resolveAliases( } ] - let vuePath = 'vue/dist/vue.esm-bundler.js' - if (!ssr) { // Prioritize vue installed in project root and fallback to // vue that comes with vitepress itself. // Only do this when not running SSR build, since `vue` needs to be // externalized during SSR + let vuePath try { vuePath = require.resolve(vueRuntimePath, { paths: [root] }) } catch (e) { vuePath = require.resolve(vueRuntimePath) } + aliases.push({ + find: /^vue$/, + replacement: vuePath + }) } - aliases.push({ - find: /^vue$/, - replacement: vuePath - }) - return aliases } diff --git a/types/default-theme.d.ts b/types/default-theme.d.ts index 5a669c49..fb736290 100644 --- a/types/default-theme.d.ts +++ b/types/default-theme.d.ts @@ -127,6 +127,11 @@ export namespace DefaultTheme { */ skipToContentLabel?: string + /** + * @default false + */ + skipTitleUpdate?: boolean + search?: | { provider: 'local'; options?: LocalSearchOptions } | { provider: 'algolia'; options: AlgoliaSearchOptions }