Skip to content

Commit bd0bdf9

Browse files
committed
feat($core): global variable "__VUEPRESS__" to store runtime key infos
1 parent 50f64b4 commit bd0bdf9

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

packages/@vuepress/core/lib/client/clientEntry.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createApp } from './app'
44

55
const { app, router } = createApp(false /* isServer */)
66

7-
window.__VUEPRESS_VERSION__ = {
7+
window.__VUEPRESS__ = {
88
version: VUEPRESS_VERSION,
99
hash: LAST_COMMIT_HASH
1010
}

packages/@vuepress/core/lib/client/components/Content.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { setGlobalInfo } from '@app/util'
12

23
export default {
34
props: {
@@ -9,6 +10,8 @@ export default {
910
},
1011
render (h) {
1112
const pageKey = this.pageKey || this.$parent.$page.key
13+
setGlobalInfo('pageKey', pageKey)
14+
1215
if (pageKey) {
1316
return h(pageKey)
1417
}

packages/@vuepress/core/lib/client/components/GlobalLayout.vue

+12-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
</template>
44

55
<script>
6+
import { setGlobalInfo } from '@app/util'
7+
68
export default {
7-
computed: {
8-
layout () {
9+
methods: {
10+
getLayout () {
911
if (this.$page.path) {
1012
const layout = this.$page.frontmatter.layout
1113
if (layout && (this.$vuepress.getLayoutAsyncComponent(layout)
@@ -16,6 +18,14 @@ export default {
1618
}
1719
return 'NotFound'
1820
}
21+
},
22+
23+
computed: {
24+
layout () {
25+
const layout = this.getLayout()
26+
setGlobalInfo('layout', layout)
27+
return layout
28+
}
1929
}
2030
}
2131
</script>

packages/@vuepress/core/lib/client/util.js

+13
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,16 @@ export function normalizeConfig (component, rawConfig) {
182182
}
183183
return rawConfig
184184
}
185+
186+
/**
187+
* Set global info in `window.__VUEPRESS__` for debugging.
188+
*
189+
* @param {string}key
190+
* @param {any} value
191+
*/
192+
export function setGlobalInfo (key, value) {
193+
if (!window.__VUEPRESS__ || typeof window === 'undefined') {
194+
return
195+
}
196+
window.__VUEPRESS__[key] = value
197+
}

0 commit comments

Comments
 (0)