From de35315c506d266f240e392b831662253a275745 Mon Sep 17 00:00:00 2001 From: ULIVZ <472590061@qq.com> Date: Mon, 11 Jun 2018 01:11:51 +0800 Subject: [PATCH] fix: duplicate description meta (close: #565) - When user set description via front-matter's meta, description generated will be duplicate which is not friendly to SEO. --- lib/app/dataMixin.js | 5 +++++ lib/build.js | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/app/dataMixin.js b/lib/app/dataMixin.js index ea8ea40c10..fd003d926f 100644 --- a/lib/app/dataMixin.js +++ b/lib/app/dataMixin.js @@ -49,6 +49,11 @@ export default function dataMixin (siteData) { : selfTitle || 'VuePress' }, $description () { + // #565 hoist description from meta + if (this.$page.frontmatter.meta) { + const descriptionMeta = this.$page.frontmatter.meta.filter(item => item.name === 'description')[0] + if (descriptionMeta) return descriptionMeta.content + } return this.$page.frontmatter.description || this.$localeConfig.description || this.$site.description || '' }, $lang () { diff --git a/lib/build.js b/lib/build.js index 33003a01c4..d43dbb5aa2 100644 --- a/lib/build.js +++ b/lib/build.js @@ -138,7 +138,10 @@ module.exports = async function build (sourceDir, cliOptions = {}) { readline.cursorTo(process.stdout, 0) process.stdout.write(`Rendering page: ${pagePath}`) - const pageMeta = renderPageMeta(page.frontmatter && page.frontmatter.meta) + // #565 avoid duplicate description + const meta = (page.frontmatter && page.frontmatter.meta || []).filter(item => item.name !== 'description') + const pageMeta = renderPageMeta(meta) + const context = { url: pagePath, userHeadTags,