astro-helmet 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/main.ts +20 -3
package/package.json
CHANGED
package/src/main.ts
CHANGED
|
@@ -146,14 +146,31 @@ function applyPriorityDefault(tag: Tag): Required<Tag> {
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
function deduplicateMetaItems(metaItems: BaseItem[]): BaseItem[] {
|
|
149
|
-
const metaMap =
|
|
149
|
+
const metaMap = groupMetaItemsByKey(metaItems)
|
|
150
|
+
return Array.from(metaMap.values()).flatMap(deduplicateByMedia)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function groupMetaItemsByKey(metaItems: BaseItem[]): Map<string, BaseItem[]> {
|
|
154
|
+
const metaMap = new Map<string, BaseItem[]>()
|
|
150
155
|
|
|
151
156
|
metaItems.forEach((meta) => {
|
|
152
157
|
const key = meta.property || meta.name || meta['http-equiv']
|
|
153
|
-
if (key) metaMap.set(key, meta)
|
|
158
|
+
if (key) metaMap.set(key, (metaMap.get(key) || []).concat(meta))
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
return metaMap
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function deduplicateByMedia(items: BaseItem[]): BaseItem[] {
|
|
165
|
+
if (items.length === 1) return items
|
|
166
|
+
|
|
167
|
+
const uniqueItems = new Map<string, BaseItem>()
|
|
168
|
+
items.forEach((item) => {
|
|
169
|
+
const mediaKey = item.media || ''
|
|
170
|
+
uniqueItems.set(mediaKey, item)
|
|
154
171
|
})
|
|
155
172
|
|
|
156
|
-
return Array.from(
|
|
173
|
+
return Array.from(uniqueItems.values())
|
|
157
174
|
}
|
|
158
175
|
|
|
159
176
|
function renderHeadTag(item: BaseItem | ContentItem): string {
|