From 52c20cf2f64519d166f7fd818e0eda44811aeb5a Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 23 Apr 2018 12:09:28 -0400 Subject: [PATCH] fix: fix title inferrence regression (close #208) --- lib/app/dataMixin.js | 12 +++++++++++- lib/app/util.js | 12 ------------ lib/default-theme/Layout.vue | 6 +++--- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/app/dataMixin.js b/lib/app/dataMixin.js index 2f3abab6b9..90036ec47a 100644 --- a/lib/app/dataMixin.js +++ b/lib/app/dataMixin.js @@ -47,7 +47,17 @@ export default { return targetLang || defaultLang || {} }, $title () { - return this.$page.frontmatter.title || this.$localeConfig.title || this.$site.title || '' + const page = this.$page + const siteTitle = this.$localeConfig.title || this.$site.title || '' + const selfTitle = page.frontmatter.home ? null : ( + page.frontmatter.title || // explicit title + page.title // inferred title + ) + return siteTitle + ? selfTitle + ? (siteTitle + ' | ' + selfTitle) + : siteTitle + : selfTitle || 'VuePress' }, $description () { return this.$page.frontmatter.description || this.$localeConfig.description || this.$site.description || '' diff --git a/lib/app/util.js b/lib/app/util.js index 0481dfec30..29643be49f 100644 --- a/lib/app/util.js +++ b/lib/app/util.js @@ -14,15 +14,3 @@ export function findPageForPath (pages, path) { } } } - -export function getTitle (siteTitle, page) { - const selfTitle = page.frontmatter.home ? null : ( - page.frontmatter.title || // explicit title - page.title // inferred title - ) - return siteTitle - ? selfTitle - ? (siteTitle + ' | ' + selfTitle) - : siteTitle - : selfTitle || 'VuePress' -} diff --git a/lib/default-theme/Layout.vue b/lib/default-theme/Layout.vue index 1119d8cf61..1abff75be6 100644 --- a/lib/default-theme/Layout.vue +++ b/lib/default-theme/Layout.vue @@ -21,7 +21,7 @@ import Home from './Home.vue' import Navbar from './Navbar.vue' import Page from './Page.vue' import Sidebar from './Sidebar.vue' -import { pathToComponentName, getTitle, getLang } from '@app/util' +import { pathToComponentName } from '@app/util' import { resolveSidebarItems } from './util' export default { @@ -76,7 +76,7 @@ export default { created () { if (this.$ssrContext) { - this.$ssrContext.title = getTitle(this.$title, this.$page) + this.$ssrContext.title = this.$title this.$ssrContext.lang = this.$lang this.$ssrContext.description = this.$page.description || this.$description } @@ -87,7 +87,7 @@ export default { // update title / meta tags this.currentMetaTags = [] const updateMeta = () => { - document.title = getTitle(this.$title, this.$page) + document.title = this.$title document.documentElement.lang = this.$lang const meta = [ {