From bd0bdf989d20ba570efaae81e9be56d2893c3da3 Mon Sep 17 00:00:00 2001 From: ULIVZ <472590061@qq.com> Date: Sun, 2 Jun 2019 22:34:57 +0800 Subject: [PATCH] feat($core): global variable "__VUEPRESS__" to store runtime key infos --- packages/@vuepress/core/lib/client/clientEntry.js | 2 +- .../core/lib/client/components/Content.js | 3 +++ .../core/lib/client/components/GlobalLayout.vue | 14 ++++++++++++-- packages/@vuepress/core/lib/client/util.js | 13 +++++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/packages/@vuepress/core/lib/client/clientEntry.js b/packages/@vuepress/core/lib/client/clientEntry.js index b7f795f613..7a8e568f5d 100644 --- a/packages/@vuepress/core/lib/client/clientEntry.js +++ b/packages/@vuepress/core/lib/client/clientEntry.js @@ -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 } diff --git a/packages/@vuepress/core/lib/client/components/Content.js b/packages/@vuepress/core/lib/client/components/Content.js index 126dba6fb2..cc06182820 100644 --- a/packages/@vuepress/core/lib/client/components/Content.js +++ b/packages/@vuepress/core/lib/client/components/Content.js @@ -1,3 +1,4 @@ +import { setGlobalInfo } from '@app/util' export default { props: { @@ -9,6 +10,8 @@ export default { }, render (h) { const pageKey = this.pageKey || this.$parent.$page.key + setGlobalInfo('pageKey', pageKey) + if (pageKey) { return h(pageKey) } diff --git a/packages/@vuepress/core/lib/client/components/GlobalLayout.vue b/packages/@vuepress/core/lib/client/components/GlobalLayout.vue index 077c65a59b..72f28a76f1 100644 --- a/packages/@vuepress/core/lib/client/components/GlobalLayout.vue +++ b/packages/@vuepress/core/lib/client/components/GlobalLayout.vue @@ -3,9 +3,11 @@ diff --git a/packages/@vuepress/core/lib/client/util.js b/packages/@vuepress/core/lib/client/util.js index 02b85feefe..65b814d783 100644 --- a/packages/@vuepress/core/lib/client/util.js +++ b/packages/@vuepress/core/lib/client/util.js @@ -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 +}