File tree 3 files changed +16
-21
lines changed
3 files changed +16
-21
lines changed Original file line number Diff line number Diff line change 1
1
export default {
2
2
created ( ) {
3
3
if ( this . $ssrContext ) {
4
- const title = getMetadata ( this , 'title' )
5
- if ( title ) {
6
- this . $ssrContext . title = title
7
- }
8
-
9
- const lang = getMetadata ( this , 'lang' )
10
- if ( lang ) {
11
- this . $ssrContext . lang = lang
12
- }
4
+ this . $ssrContext . title = getMetadata ( this , 'title' ) || 'VuePress'
5
+ this . $ssrContext . lang = getMetadata ( this , 'lang' ) || 'en'
13
6
}
14
7
} ,
15
8
mounted ( ) {
16
- const title = getMetadata ( this , 'title' )
17
- if ( title ) {
18
- document . title = title
19
- }
20
-
21
- const lang = getMetadata ( this , 'lang' )
22
- if ( lang ) {
23
- document . documentElement . lang = lang
9
+ const updateMeta = ( ) => {
10
+ document . title = getMetadata ( this , 'title' ) || 'VuePress'
11
+ document . documentElement . lang = getMetadata ( this , 'lang' ) || 'en'
24
12
}
13
+ this . $watch ( '$page' , updateMeta )
14
+ updateMeta ( )
25
15
} ,
26
16
render ( h ) {
27
17
const componentName = this . $page . path === '/'
@@ -35,5 +25,5 @@ export default {
35
25
}
36
26
37
27
function getMetadata ( vm , key ) {
38
- return vm . $page . frontmatter [ key ] || vm . $page [ key ]
28
+ return vm . $page . frontmatter [ key ] || vm . $page [ key ] || vm . $site [ key ]
39
29
}
Original file line number Diff line number Diff line change @@ -47,9 +47,7 @@ module.exports = async function build (sourceDir) {
47
47
await Promise . all ( options . siteData . pages . map ( async ( page ) => {
48
48
const context = {
49
49
url : page . path ,
50
- userHeadTags,
51
- title : 'VuePress' ,
52
- lang : 'en'
50
+ userHeadTags
53
51
}
54
52
55
53
let html
Original file line number Diff line number Diff line change @@ -60,7 +60,14 @@ async function resolveOptions (sourceDir) {
60
60
const data = {
61
61
path : urlPath
62
62
}
63
+
64
+ // extract yaml frontmatter
63
65
const frontmatter = yaml . loadFront ( content )
66
+ // infer title
67
+ const titleMatch = frontmatter . __content . match ( / ^ # + \s + ( .* ) / )
68
+ if ( titleMatch ) {
69
+ data . title = titleMatch [ 1 ]
70
+ }
64
71
delete frontmatter . __content
65
72
if ( Object . keys ( frontmatter ) . length ) {
66
73
data . frontmatter = frontmatter
You can’t perform that action at this time.
0 commit comments