Vuepress: Overriding global meta description

Created on 17 Apr 2018  路  7Comments  路  Source: vuejs/vuepress

If I define a meta-description (frontmatter) in a page, it does not seem to override the meta-description defined in .vuepress/config.js

.vuepress/config.js

module.exports = {
  title: 'vuepress is awesome',
  description: 'this should be the default description for pages that do not define their own meta descriptions',
};

Example page

---
meta:
  - name: description
    content: my custom meta description
---

I would expect that my custom meta description is rendered, but the default description from .vuepress/config.js and the frontmatter-description are rendered.

These are the code parts that seem to be responsible for the page-meta processing:
https://github.com/vuejs/vuepress/blob/1bbfa43f0b457d59d6445184f6e7f21713e97869/lib/prepare.js#L76
https://github.com/vuejs/vuepress/blob/1bbfa43f0b457d59d6445184f6e7f21713e97869/lib/build.js#L131
https://github.com/vuejs/vuepress/blob/1bbfa43f0b457d59d6445184f6e7f21713e97869/lib/build.js#L153

I'm not sure how to tackle this issue... maybe we could inject the global description into the page.frontmatter.meta object instead of the siteConfig.head object? Something like this:

// lib/prepare.js
const frontmatter = yaml.loadFront(content)
if (siteConfig.description && !frontmatter.meta.description) {
    frontmatter.meta.description = siteConfig.description
}
bug

All 7 comments

In fact, at current build flow, the description will be gennerated twice:

image

I also realized this problem, and description meta tag has been handled at #48,

I thought I'd open a PR to fix it alone, but because the multiple language support would also change it for different locale, I just added a patch(961cf2d9ee882465af9673a7ed343c9d081ff5d9) and fixed your problem quickly.

After @ulivz's fix the generated static files should all have correct meta. Currently during dev or after a dynamic navigation it will still have duplicated description, but for SEO purposes that probably doesn't matter.

Closed via #48

Thanks for your awesome support! :heart:

It seems that this bug is still there. I get the global and the page-specific decription on my pages. This is very bad for SEO. 馃檨

<meta name="description" content="From global">
<meta name="description" content="From page">

@AWulkan Please create an issue with the correct reproduction link 馃檪

@ulivz I've created one here now: https://github.com/vuejs/vuepress/issues/565

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tinchox5 picture tinchox5  路  3Comments

genedronek picture genedronek  路  3Comments

harryhorton picture harryhorton  路  3Comments

ynnelson picture ynnelson  路  3Comments

lesliecdubs picture lesliecdubs  路  3Comments