Skip to content

Commit c27c506

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

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

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

+18-2
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,26 @@ export default {
3535

3636
getMergedMetaTags () {
3737
const pageMeta = this.$page.frontmatter.meta || []
38+
const templateMeta = []
39+
if (typeof document !== 'undefined') {
40+
const templateMetaTags = document.querySelectorAll('meta')
41+
templateMetaTags.forEach(tag => {
42+
const names = tag.getAttributeNames()
43+
if (names.length === 1) {
44+
const attr = tag.getAttributeNames()[0]
45+
const obj = {}
46+
obj[attr] = tag.getAttribute(attr)
47+
templateMeta.push(obj)
48+
} else if (names.every(e => ['name', 'content'].includes(e))) {
49+
templateMeta.push({ name: tag.name, content: tag.content })
50+
} else if (names.every(e => ['http-equiv', 'content'].includes(e))) {
51+
templateMeta.push({ 'http-equiv': tag.httpEquiv, content: tag.content })
52+
}
53+
})
54+
}
3855
// pageMetaTags have higher priority than siteMetaTags
3956
// description needs special attention as it has too many entries
40-
return unionBy([{ name: 'description', content: this.$description }],
41-
pageMeta, this.siteMeta, metaIdentifier)
57+
return unionBy([{ name: 'description', content: this.$description }], pageMeta, this.siteMeta, templateMeta, metaIdentifier)
4258
}
4359
},
4460

0 commit comments

Comments
 (0)