diff --git a/src/client/app/composables/head.ts b/src/client/app/composables/head.ts index 849fb3b8..2d6ad39b 100644 --- a/src/client/app/composables/head.ts +++ b/src/client/app/composables/head.ts @@ -3,69 +3,19 @@ import { HeadConfig, SiteData, processHead } from '../../shared' import { Route } from '../router' export function useUpdateHead(route: Route, siteDataByRouteRef: Ref) { - let managedHeadTags: HTMLElement[] = [] - let isFirstUpdate = true - - const updateHeadTags = (newTags: HeadConfig[]) => { - if (import.meta.env.PROD && isFirstUpdate) { - // in production, the initial meta tags are already pre-rendered so we - // skip the first update. - isFirstUpdate = false - return - } - - const newEls: HTMLElement[] = [] - const commonLength = Math.min(managedHeadTags.length, newTags.length) - for (let i = 0; i < commonLength; i++) { - let el = managedHeadTags[i] - const [tag, attrs, innerHTML = ''] = newTags[i] - if (el.tagName.toLocaleLowerCase() === tag) { - for (const key in attrs) { - if (el.getAttribute(key) !== attrs[key]) { - el.setAttribute(key, attrs[key]) - } - } - for (let i = 0; i < el.attributes.length; i++) { - const name = el.attributes[i].name - if (!(name in attrs)) { - el.removeAttribute(name) - } - } - if (el.innerHTML !== innerHTML) { - el.innerHTML = innerHTML - } - } else { - document.head.removeChild(el) - el = createHeadElement(newTags[i]) - document.head.append(el) - } - newEls.push(el) - } - - managedHeadTags - .slice(commonLength) - .forEach((el) => document.head.removeChild(el)) - newTags.slice(commonLength).forEach((headConfig) => { - const el = createHeadElement(headConfig) - document.head.appendChild(el) - newEls.push(el) - }) - managedHeadTags = newEls - } watchEffect(() => { const pageData = route.data const siteData = siteDataByRouteRef.value const pageTitle = pageData && pageData.title - //const pageDescription = pageData && pageData.description + const pageDescription = pageData && pageData.description // update title and description document.title = (pageTitle ? pageTitle + ` | ` : ``) + siteData.title document .querySelector(`meta[name=description]`)! - .setAttribute('content', JSON.stringify(siteData.head))//pageDescription || siteData.description) + .setAttribute('content', pageDescription || siteData.description) - updateHeadTags(processHead(siteData.head, pageData)) }) } diff --git a/src/client/app/data.ts b/src/client/app/data.ts index 82c149a7..a3ce5369 100644 --- a/src/client/app/data.ts +++ b/src/client/app/data.ts @@ -3,7 +3,6 @@ import { Route } from './router' import serializedSiteData from '@siteData' import { resolveSiteDataByRoute, PageData, SiteData } from '../shared' import { withBase } from './utils' -import { HeadConfig } from 'dist/vitepress' export const dataSymbol: InjectionKey = Symbol() @@ -11,7 +10,6 @@ export interface VitePressData { site: Ref> page: Ref theme: Ref - head: Ref HeadConfig[])> frontmatter: Ref title: Ref description: Ref @@ -45,7 +43,6 @@ export function initData(route: Route): VitePressData { return { site, theme: computed(() => site.value.themeConfig), - head: computed(() => site.value.head), page: computed(() => route.data), frontmatter: computed(() => route.data.frontmatter), lang: computed(() => site.value.lang),