From e4e238cdda2fdeebcd5f7988af1e4f2ce3ad243a Mon Sep 17 00:00:00 2001 From: Xinyu Liu Date: Thu, 10 May 2018 08:46:01 +0800 Subject: [PATCH 1/2] fix: computed parsing errors in notfound --- lib/app/util.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/app/util.js b/lib/app/util.js index 29643be49f..e1229ad1d8 100644 --- a/lib/app/util.js +++ b/lib/app/util.js @@ -13,4 +13,8 @@ export function findPageForPath (pages, path) { return page } } + return { + path: '', + frontmatter: {} + } } From 707fc3e033671df6e376de3a7d3d38802bfae31a Mon Sep 17 00:00:00 2001 From: Xinyu Liu Date: Thu, 10 May 2018 09:19:10 +0800 Subject: [PATCH 2/2] fix: move ssrContext into theme wrapper --- lib/app/ThemeWrapper.vue | 62 ++++++++++++++++++++++++++++++++++++ lib/default-theme/Layout.vue | 45 -------------------------- lib/prepare.js | 7 ++-- 3 files changed, 65 insertions(+), 49 deletions(-) create mode 100644 lib/app/ThemeWrapper.vue diff --git a/lib/app/ThemeWrapper.vue b/lib/app/ThemeWrapper.vue new file mode 100644 index 0000000000..102b518b67 --- /dev/null +++ b/lib/app/ThemeWrapper.vue @@ -0,0 +1,62 @@ + + + + diff --git a/lib/default-theme/Layout.vue b/lib/default-theme/Layout.vue index df988d69d7..9e54d0f248 100644 --- a/lib/default-theme/Layout.vue +++ b/lib/default-theme/Layout.vue @@ -87,32 +87,7 @@ export default { } }, - created () { - if (this.$ssrContext) { - this.$ssrContext.title = this.$title - this.$ssrContext.lang = this.$lang - this.$ssrContext.description = this.$page.description || this.$description - } - }, - mounted () { - // update title / meta tags - this.currentMetaTags = [] - const updateMeta = () => { - document.title = this.$title - document.documentElement.lang = this.$lang - const meta = [ - { - name: 'description', - content: this.$description - }, - ...(this.$page.frontmatter.meta || []) - ] - this.currentMetaTags = updateMetaTags(meta, this.currentMetaTags) - } - this.$watch('$page', updateMeta) - updateMeta() - window.addEventListener('scroll', this.onScroll) // configure progress bar @@ -132,8 +107,6 @@ export default { }, beforeDestroy () { - updateMetaTags(null, this.currentMetaTags) - window.removeEventListener('scroll', this.onScroll) }, @@ -191,24 +164,6 @@ export default { } } } - -function updateMetaTags (meta, current) { - if (current) { - current.forEach(c => { - document.head.removeChild(c) - }) - } - if (meta) { - return meta.map(m => { - const tag = document.createElement('meta') - Object.keys(m).forEach(key => { - tag.setAttribute(key, m[key]) - }) - document.head.appendChild(tag) - return tag - }) - } -} diff --git a/lib/prepare.js b/lib/prepare.js index 49186a82d0..45c50ed654 100644 --- a/lib/prepare.js +++ b/lib/prepare.js @@ -311,7 +311,7 @@ async function genRoutesFile ({ siteData: { pages }, sourceDir, pageFiles }) { let code = ` { path: ${JSON.stringify(pagePath)}, - component: ThemeLayout, + component: ThemeWrapper, beforeEnter: (to, from, next) => { import(${JSON.stringify(filePath)}).then(comp => { Vue.component(${JSON.stringify(fileToComponentName(file))}, comp.default) @@ -334,12 +334,11 @@ async function genRoutesFile ({ siteData: { pages }, sourceDir, pageFiles }) { const notFoundRoute = `, { path: '*', - component: ThemeNotFound + component: ThemeWrapper }` return ( - `import ThemeLayout from '@themeLayout'\n` + - `import ThemeNotFound from '@themeNotFound'\n` + + `import ThemeWrapper from '@app/ThemeWrapper'\n` + `export const routes = [${pages.map(genRoute).join(',')}${notFoundRoute}\n]` ) }