Skip to content

Commit 552aaf2

Browse files
committed
change meta tags merge function
1 parent 87f1bae commit 552aaf2

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

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

+14-26
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
1-
import unionBy from 'lodash/unionBy'
2-
3-
// @see https://ogp.me/
4-
const META_TYPE_ARRAY = [
5-
'article:author',
6-
'article:tag',
7-
'book:author',
8-
'book:tag',
9-
'music:album',
10-
'music:musician',
11-
'og:locale:alternate',
12-
'video:actor',
13-
'video:director',
14-
'video:tag',
15-
'video:writer'
16-
]
1+
import transform from 'lodash/transform'
172

183
export default {
194
// created will be called on both client and ssr
@@ -49,11 +34,18 @@ export default {
4934
},
5035

5136
getMergedMetaTags () {
52-
const pageMeta = this.$page.frontmatter.meta || []
53-
// pageMetaTags have higher priority than siteMetaTags
54-
// description needs special attention as it has too many entries
55-
return unionBy([{ name: 'description', content: this.$description }],
56-
pageMeta, this.siteMeta, metaIdentifier)
37+
const exists = {}
38+
return transform([
39+
this.$page.frontmatter.meta || [], // page meta
40+
[{ name: 'description', content: this.$description }], // meta description
41+
this.siteMeta // site meta
42+
], (merged, meta) => {
43+
const filtered = meta.filter(tag => !exists[metaIdentifier(tag)])
44+
merged.push(...filtered)
45+
filtered.forEach(tag => {
46+
exists[metaIdentifier(tag)] = 1
47+
})
48+
}, [])
5749
}
5850
},
5951

@@ -101,11 +93,7 @@ function updateMetaTags (newMetaTags, currentMetaTags) {
10193
*/
10294
function metaIdentifier (tag) {
10395
for (const item of ['name', 'property', 'itemprop']) {
104-
if (tag.hasOwnProperty(item)) {
105-
const key = tag[item]
106-
const value = tag.hasOwnProperty('content') && ~META_TYPE_ARRAY.indexOf(key) ? tag.content : ''
107-
return key + item + value
108-
}
96+
if (tag.hasOwnProperty(item)) return tag[item] + item
10997
}
11098
return JSON.stringify(tag)
11199
}

0 commit comments

Comments
 (0)