MCPcopy
hub / github.com/vuepress/core / resolveHeadIdentifier

Function resolveHeadIdentifier

packages/shared/src/utils/resolveHeadIdentifier.ts:9–46  ·  view source on GitHub ↗
([tag, attrs, content]: HeadConfig)

Source from the content-addressed store, hash-verified

7 * Resolve identifier of a tag, to avoid duplicated tags in `<head>`
8 */
9export const resolveHeadIdentifier = ([tag, attrs, content]: HeadConfig):
10 | string
11 | null => {
12 // avoid duplicated unique tags
13 if (TAGS_UNIQUE.includes(tag)) {
14 return tag
15 }
16
17 // avoid disallowed tags
18 if (!TAGS_ALLOWED.includes(tag)) {
19 return null
20 }
21
22 // avoid duplicated `<meta>` with same `name`
23 if (tag === 'meta' && attrs.name) {
24 return `${tag}.${attrs.name}`
25 }
26
27 // avoid duplicated `<template>` with same `id`
28 if (tag === 'template' && attrs.id) {
29 return `${tag}.${attrs.id}`
30 }
31
32 return JSON.stringify([
33 tag,
34 Object.entries(attrs)
35 .map(([key, value]) => {
36 // normalize boolean attributes
37 if (typeof value === 'boolean') {
38 return value ? [key, ''] : null
39 }
40 return [key, value]
41 })
42 .filter((item): item is [string, string] => item != null)
43 .sort(([keyA], [keyB]) => keyA.localeCompare(keyB)),
44 content,
45 ])
46}

Callers 2

dedupeHeadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected