mirror of https://github.com/vuejs/vitepress
Any element with an `id` is keyed by it regardless of attribute order, and a `meta` without one is keyed by its first attribute other than `content`. This stops differently named meta tags with the same content from overriding each other and lets repeated meta tags be kept apart with unique ids. fixes #5362 closes #5363 closes #5379 Co-authored-by: Lazizbek Ergashev <20501725+lazerg@users.noreply.github.com> Co-authored-by: shamu45678 <220251922@seu.edu.cn> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>pull/4532/merge
parent
ed03db9a59
commit
b18f30680b
@ -0,0 +1,56 @@
|
|||||||
|
import { mergeHead, type HeadConfig } from 'shared/shared'
|
||||||
|
|
||||||
|
describe('shared/shared', () => {
|
||||||
|
describe('mergeHead', () => {
|
||||||
|
test('replaces meta tags with the same key in place', () => {
|
||||||
|
expect(
|
||||||
|
mergeHead(
|
||||||
|
[
|
||||||
|
['meta', { property: 'og:image', content: '/site.png' }],
|
||||||
|
['meta', { name: 'keywords', content: 'site' }]
|
||||||
|
],
|
||||||
|
[['meta', { content: '/page.png', property: 'og:image' }]]
|
||||||
|
)
|
||||||
|
).toEqual([
|
||||||
|
['meta', { content: '/page.png', property: 'og:image' }],
|
||||||
|
['meta', { name: 'keywords', content: 'site' }]
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('ignores content when keying meta tags', () => {
|
||||||
|
const head: HeadConfig[] = [
|
||||||
|
['meta', { content: 'a', name: 'name1' }],
|
||||||
|
['meta', { content: 'a', name: 'name2' }]
|
||||||
|
]
|
||||||
|
expect(mergeHead(head)).toEqual(head)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('keys any element by id regardless of attribute order', () => {
|
||||||
|
expect(
|
||||||
|
mergeHead(
|
||||||
|
[
|
||||||
|
['meta', { name: 'author', content: 'a', id: 'author-a' }],
|
||||||
|
['meta', { name: 'author', content: 'b', id: 'author-b' }],
|
||||||
|
['script', { id: 'sw' }, 'old']
|
||||||
|
],
|
||||||
|
[
|
||||||
|
['meta', { id: 'author-a', name: 'author', content: 'c' }],
|
||||||
|
['script', { id: 'sw' }, 'new']
|
||||||
|
]
|
||||||
|
)
|
||||||
|
).toEqual([
|
||||||
|
['meta', { id: 'author-a', name: 'author', content: 'c' }],
|
||||||
|
['meta', { name: 'author', content: 'b', id: 'author-b' }],
|
||||||
|
['script', { id: 'sw' }, 'new']
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('appends elements without a key', () => {
|
||||||
|
const head: HeadConfig[] = [
|
||||||
|
['link', { rel: 'stylesheet', href: '/a.css' }],
|
||||||
|
['link', { rel: 'stylesheet', href: '/a.css' }]
|
||||||
|
]
|
||||||
|
expect(mergeHead(head, head)).toEqual([...head, ...head])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
Loading…
Reference in new issue