Docusaurus: [V2] Custom frontmatter/metadata is no longer available

Created on 2 Dec 2019  ·  5Comments  ·  Source: facebook/docusaurus

🐛 Bug Report

Custom frontmatter/metadata defined in markdown files is no longer accessible within the DocItem component when it previously was.

It appears this change broke the behavior.

Have you read the Contributing Guidelines on issues?

Yes

To Reproduce

  1. Add a custom frontmatter field in a blog post or documentation markdown file.
  2. The property is no longer available in this object.

Expected behavior

Frontmatter, by nature, should allow for a variety of keys, especially a platform designed to serve a variety of different project types.

bug needs triage

All 5 comments

Its not a bug. Its actually a bug that got fixed.

https://github.com/facebook/docusaurus/blob/8a948102c3e31abcdfd6ee32a8e1d8e4b057c4c4/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.ts#L115

Its never been documented anyway that you can access frontmatter through metadata. Even in v1 it will throw error if you add unsupported field.

You should not access frontmatter from metadata. Metadata is something done by plugin.

Example: /docs/guides/hello.md defined with frontmatter id: “hello” will have a metadata.id of “guides/hello”

If you want to access frontmatter, do it through content.frontmatter

reasoning is here

https://github.com/facebook/docusaurus/pull/1450

Clean up blog data props structure by splitting metadata and front matter into two separate props. This is helpful in letting users add whatever they want to the front matter and have it being referenced in blog posts. Metadata is something that is controlled by the plugin. There will not be collisions if we split it up. For blog list pages, I've also cleaned them up a bit and reused the blog item metadata and front matter. It was being duplicated in the list's metadata and the entries 😓

Thanks, I must have been using an older version of DocItem/index.js because the frontMatter definition was not included.

@binarylogic We would discourage swizzling components at this point until we reach beta or even 2.0.0 for this very reason. Apologies for the changes.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cameronelliott picture cameronelliott  ·  28Comments

wgao19 picture wgao19  ·  31Comments

knowbody picture knowbody  ·  23Comments

slorber picture slorber  ·  23Comments

KoenCa picture KoenCa  ·  25Comments