Skip to content

Commit

Permalink
refactor: simplify head tracking logic
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Jan 20, 2024
1 parent ba3c644 commit 9008727
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/client/app/composables/head.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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('')}`
}

0 comments on commit 9008727

Please sign in to comment.