diff --git a/packages/zhead/src/tagDedupeKey.ts b/packages/zhead/src/tagDedupeKey.ts index 1dd6d82..42b52b0 100644 --- a/packages/zhead/src/tagDedupeKey.ts +++ b/packages/zhead/src/tagDedupeKey.ts @@ -9,7 +9,11 @@ const ArrayMetaProperties = [ 'music:album', 'music:musician', ] -export function tagDedupeKey(tag: T): string | false { +export function tagDedupeKeyWithMetaProps(tag: T): string | false { + return tagDedupeKey(tag, (val) => ArrayMetaProperties.findIndex(p => val.startsWith(p)) === -1) +} + +export function tagDedupeKey(tag: T, fn?: (key: string) => boolean): string | false { const { props, tag: tagName } = tag // must only be a single base so we always dedupe if (UniqueTags.includes(tagName)) @@ -30,7 +34,7 @@ export function tagDedupeKey(tag: T): string | false { // open graph props can have multiple tags with the same property if (typeof props[n] !== 'undefined') { const val = String(props[n]) - if (ArrayMetaProperties.findIndex(p => val.startsWith(p)) !== -1) + if (fn && !fn(val)) return false // for example: meta-name-description return `${tagName}:${n}:${val}` diff --git a/test/zhead/tagDedupeKey.test.ts b/test/zhead/tagDedupeKey.test.ts index f4d01f4..ff43bbf 100644 --- a/test/zhead/tagDedupeKey.test.ts +++ b/test/zhead/tagDedupeKey.test.ts @@ -1,4 +1,4 @@ -import { tagDedupeKey } from 'zhead' +import {tagDedupeKey, tagDedupeKeyWithMetaProps} from 'zhead' describe('tagDedupeKey', () => { test('title key', async () => { @@ -63,7 +63,7 @@ describe('tagDedupeKey', () => { }) test('og exception', async () => { - const key = tagDedupeKey({ + const key = tagDedupeKeyWithMetaProps({ tag: 'meta', props: { property: 'og:image',