Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding global meta description #112

Closed
jaylinski opened this issue Apr 17, 2018 · 7 comments
Closed

Overriding global meta description #112

jaylinski opened this issue Apr 17, 2018 · 7 comments
Labels
type: bug Something isn't working

Comments

@jaylinski
Copy link
Contributor

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:

'meta', { name: 'description', content: siteConfig.description }

const pageMeta = renderPageMeta(page.frontmatter && page.frontmatter.meta)

function renderPageMeta (meta) {

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
}
@yyx990803 yyx990803 added the type: bug Something isn't working label Apr 18, 2018
@ulivz
Copy link
Member

ulivz commented Apr 18, 2018

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(961cf2d) and fixed your problem quickly.

@yyx990803
Copy link
Member

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.

@yyx990803
Copy link
Member

Closed via #48

@jaylinski
Copy link
Contributor Author

Thanks for your awesome support! ❤️

@awulkan
Copy link

awulkan commented Jun 10, 2018

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">

@ulivz
Copy link
Member

ulivz commented Jun 10, 2018

@awulkan Please create an issue with the correct reproduction link 🙂

@awulkan
Copy link

awulkan commented Jun 10, 2018

@ulivz I've created one here now: #565

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants