@@ -6,32 +6,43 @@ export default {
6
6
this . $ssrContext . description = this . $page . description || this . $description
7
7
}
8
8
} ,
9
+
9
10
mounted ( ) {
10
11
// update title / meta tags
11
- this . currentMetaTags = [ ]
12
+ this . currentMetaTags = new Set ( )
13
+
12
14
const updateMeta = ( ) => {
13
15
document . title = this . $title
14
16
document . documentElement . lang = this . $lang
15
- const meta = [
16
- {
17
- name : 'description' ,
18
- content : this . $description
19
- } ,
20
- ...( this . $page . frontmatter . meta || [ ] )
21
- ]
22
- this . currentMetaTags = updateMetaTags ( meta , this . currentMetaTags )
17
+ const userMeta = this . $page . frontmatter . meta || [ ]
18
+ const meta = userMeta . slice ( 0 )
19
+ const useGlobalDescription = userMeta . filter ( m => m . name === 'description' ) . length === 0
20
+
21
+ // #665 Avoid duplicate description meta at runtime.
22
+ if ( useGlobalDescription ) {
23
+ meta . push ( { name : 'description' , content : this . $description } )
24
+ }
25
+
26
+ // Including description meta coming from SSR.
27
+ const descriptionMetas = document . querySelectorAll ( 'meta[name="description"]' )
28
+ if ( descriptionMetas . length ) {
29
+ descriptionMetas . forEach ( m => this . currentMetaTags . add ( m ) )
30
+ }
31
+
32
+ this . currentMetaTags = new Set ( updateMetaTags ( meta , this . currentMetaTags ) )
23
33
}
24
34
this . $watch ( '$page' , updateMeta )
25
35
updateMeta ( )
26
36
} ,
37
+
27
38
beforeDestroy ( ) {
28
39
updateMetaTags ( null , this . currentMetaTags )
29
40
}
30
41
}
31
42
32
43
function updateMetaTags ( meta , current ) {
33
44
if ( current ) {
34
- current . forEach ( c => {
45
+ [ ... current ] . forEach ( c => {
35
46
document . head . removeChild ( c )
36
47
} )
37
48
}
0 commit comments