Skip to content

Commit bf7d10c

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

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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

+9-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ export default {
1717
},
1818
// Other life cycles will only be called at client
1919
mounted () {
20-
// init currentMetaTags from DOM
21-
this.currentMetaTags = [...document.querySelectorAll('meta')]
20+
// init currentMetaTags from pageMeta
21+
this.currentMetaTags = this.getMergedMetaTags().map(m => {
22+
let selector = 'meta'
23+
for (const [key, value] of Object.entries(m)) {
24+
selector += `[${key}="${value}"]`
25+
}
26+
return [...document.querySelectorAll(selector)]
27+
}).flat()
2228

2329
// update title / meta tags
2430
this.updateMeta()
@@ -37,8 +43,7 @@ export default {
3743
const pageMeta = this.$page.frontmatter.meta || []
3844
// pageMetaTags have higher priority than siteMetaTags
3945
// description needs special attention as it has too many entries
40-
return unionBy([{ name: 'description', content: this.$description }],
41-
pageMeta, this.siteMeta, metaIdentifier)
46+
return unionBy([{ name: 'description', content: this.$description }], pageMeta, this.siteMeta, metaIdentifier)
4247
}
4348
},
4449

0 commit comments

Comments
 (0)