Skip to content

Commit 1cef33f

Browse files
committed
fix($core): preserve original meta charset and viewport (#2332)
1 parent f54b389 commit 1cef33f

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Diff for: packages/@vuepress/core/lib/client/root-mixins/updateMeta.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,26 @@ export default {
3737
const pageMeta = this.$page.frontmatter.meta || []
3838
// pageMetaTags have higher priority than siteMetaTags
3939
// description needs special attention as it has too many entries
40-
return unionBy([{ name: 'description', content: this.$description }],
41-
pageMeta, this.siteMeta, metaIdentifier)
40+
const templateMeta = []
41+
if (typeof document !== 'undefined') {
42+
const templateMetaTags = document.querySelectorAll('meta')
43+
templateMetaTags.forEach(tag => {
44+
const names = tag.getAttributeNames()
45+
if (names.length === 1) {
46+
const attr = tag.getAttributeNames()[0]
47+
const obj = {}
48+
obj[attr] = tag.getAttribute(attr)
49+
templateMeta.push(obj)
50+
} else if (names.every(e => ['name', 'content'].includes(e))) {
51+
templateMeta.push({ name: tag.name, content: tag.content })
52+
} else if (names.every(e => ['http-equiv', 'content'].includes(e))) {
53+
templateMeta.push({ 'http-equiv': tag.httpEquiv, content: tag.content })
54+
}
55+
})
56+
}
57+
// pageMetaTags have higher priority than siteMetaTags
58+
// description needs special attention as it has too many entries
59+
return unionBy([{ name: 'description', content: this.$description }], pageMeta, this.siteMeta, templateMeta, metaIdentifier)
4260
}
4361
},
4462

0 commit comments

Comments
 (0)