File tree Expand file tree Collapse file tree 7 files changed +17
-35
lines changed
@vuepress/core/lib/client Expand file tree Collapse file tree 7 files changed +17
-35
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ export default {
8
8
} ,
9
9
render ( h ) {
10
10
const pageKey = this . pageKey || this . $parent . $page . key
11
- if ( this . $vuepress . isPageExists ( pageKey ) ) {
11
+ if ( this . $hasComponent ( pageKey ) ) {
12
12
return h ( pageKey )
13
13
}
14
14
return h ( '' )
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ export default {
7
7
computed: {
8
8
layout () {
9
9
if (this .$page .path ) {
10
- if (this .$vuepress . isLayoutExists (this .$page .frontmatter .layout )) {
10
+ if (this .$hasComponent (this .$page .frontmatter .layout )) {
11
11
return this .$page .frontmatter .layout
12
12
}
13
13
return ' Layout'
Original file line number Diff line number Diff line change 1
1
import Vue from 'Vue'
2
2
3
3
export declare class Store {
4
- store : Vue ;
4
+ store : Vue
5
5
6
- $get ( key : string ) : any ;
6
+ $get ( key : string ) : any
7
7
8
- $set ( key : string , value : any ) : void ;
8
+ $set ( key : string , value : any ) : void
9
9
10
- $emit : typeof Vue . prototype . $emit ;
10
+ $emit : typeof Vue . prototype . $emit
11
11
12
- $on : typeof Vue . prototype . $on ;
12
+ $on : typeof Vue . prototype . $on
13
13
}
14
-
15
-
Original file line number Diff line number Diff line change 1
- import { Store } from './Store' ;
2
- import { AsyncComponent } from 'vue'
1
+ import { Store } from './Store'
3
2
4
- declare class VuePress extends Store {
5
- isPageExists ( pageKey : string ) : boolean ;
6
-
7
- isLayoutExists ( pageKey : string ) : boolean ;
8
- }
9
-
10
- declare module "vue/types/vue" {
3
+ declare module 'vue/types/vue' {
11
4
export interface Vue {
12
- $vuepress : VuePress ;
5
+ $vuepress : Store
6
+ $hasComponent ( key : string ) : boolean
13
7
}
14
8
}
Original file line number Diff line number Diff line change 1
- import Vue from 'vue'
2
1
import Store from './Store'
3
2
4
3
// TODO: reuse this function in shared-utils
@@ -14,20 +13,11 @@ function cached (fn) {
14
13
15
14
const pascalize = cached ( ( str = '' ) => str . replace ( / ( ^ | - ) \w / g, s => s . slice ( - 1 ) . toUpperCase ( ) ) )
16
15
17
- class VuePress extends Store {
18
- isPageExists ( pageKey ) {
19
- return Boolean ( Vue . component ( pascalize ( pageKey ) ) )
20
- }
21
-
22
- isLayoutExists ( layout ) {
23
- return Boolean ( Vue . component ( pascalize ( layout ) ) )
24
- }
25
- }
26
-
27
16
export default {
28
17
install ( Vue ) {
29
- const ins = new VuePress ( )
30
- Vue . $vuepress = ins
31
- Vue . prototype . $vuepress = ins
18
+ const vuepress = new Store ( )
19
+ Vue . $vuepress = vuepress
20
+ Vue . prototype . $vuepress = vuepress
21
+ Vue . prototype . $hasComponent = key => Boolean ( Vue . component ( pascalize ( key ) ) )
32
22
}
33
23
}
Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ export default {
111
111
computed: {
112
112
layout () {
113
113
if (this.$page.path) {
114
- if (this.$vuepress.isLayoutExists (this.$frontmatter.layout)) {
114
+ if (this.$hasComponent (this.$frontmatter.layout)) {
115
115
return this.$frontmatter.layout
116
116
}
117
117
return 'Layout'
Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ export default {
111
111
computed: {
112
112
layout () {
113
113
if (this.$page.path) {
114
- if (this.$vuepress.isLayoutExists (this.$frontmatter.layout)) {
114
+ if (this.$hasComponent (this.$frontmatter.layout)) {
115
115
return this.$frontmatter.layout
116
116
}
117
117
return 'Layout'
You can’t perform that action at this time.
0 commit comments