Skip to content

Commit

Permalink
feat($core): global variable "__VUEPRESS__" to store runtime key infos
Browse files Browse the repository at this point in the history
  • Loading branch information
ulivz committed Jun 2, 2019
1 parent 50f64b4 commit bd0bdf9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/@vuepress/core/lib/client/clientEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createApp } from './app'

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

window.__VUEPRESS_VERSION__ = {
window.__VUEPRESS__ = {
version: VUEPRESS_VERSION,
hash: LAST_COMMIT_HASH
}
Expand Down
3 changes: 3 additions & 0 deletions packages/@vuepress/core/lib/client/components/Content.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setGlobalInfo } from '@app/util'

export default {
props: {
Expand All @@ -9,6 +10,8 @@ export default {
},
render (h) {
const pageKey = this.pageKey || this.$parent.$page.key
setGlobalInfo('pageKey', pageKey)

if (pageKey) {
return h(pageKey)
}
Expand Down
14 changes: 12 additions & 2 deletions packages/@vuepress/core/lib/client/components/GlobalLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
</template>

<script>
import { setGlobalInfo } from '@app/util'
export default {
computed: {
layout () {
methods: {
getLayout () {
if (this.$page.path) {
const layout = this.$page.frontmatter.layout
if (layout && (this.$vuepress.getLayoutAsyncComponent(layout)
Expand All @@ -16,6 +18,14 @@ export default {
}
return 'NotFound'
}
},
computed: {
layout () {
const layout = this.getLayout()
setGlobalInfo('layout', layout)
return layout
}
}
}
</script>
13 changes: 13 additions & 0 deletions packages/@vuepress/core/lib/client/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,16 @@ export function normalizeConfig (component, rawConfig) {
}
return rawConfig
}

/**
* Set global info in `window.__VUEPRESS__` for debugging.
*
* @param {string}key
* @param {any} value
*/
export function setGlobalInfo (key, value) {
if (!window.__VUEPRESS__ || typeof window === 'undefined') {
return
}
window.__VUEPRESS__[key] = value
}

0 comments on commit bd0bdf9

Please sign in to comment.