refactor: simplify head tracking logic

pull/3488/head
Divyansh Singh 11 months ago
parent ba3c6441be
commit 900872769e

@ -17,14 +17,13 @@ export function useUpdateHead(route: Route, siteDataByRouteRef: Ref<SiteData>) {
// skip the first update.
isFirstUpdate = false
newTags.forEach((tag) => {
const selector = toSelector(tag[0], tag[1])
const headEl = createHeadElement(tag)
;[...document.querySelectorAll(selector)].some((el) => {
for (const el of document.head.children) {
if (el.isEqualNode(headEl)) {
managedHeadElements.push(el as HTMLElement)
return true
return
}
})
}
})
return
}
@ -106,9 +105,3 @@ function isMetaDescription(headConfig: HeadConfig) {
function filterOutHeadDescription(head: HeadConfig[]) {
return head.filter((h) => !isMetaDescription(h))
}
function toSelector(tag: string, attrs: Record<string, string>) {
return `${tag}${Object.keys(attrs)
.map((key) => `[${key}="${attrs[key].replace(/(["'\\])/g, '\\$1')}"]`)
.join('')}`
}

Loading…
Cancel
Save