8000 Proposal: enable option to propagate arbitrary frontmatter data in globals · Issue #4492 · facebook/docusaurus · GitHub
[go: up one dir, main page]

Skip to content

Proposal: enable option to propagate arbitrary frontmatter data in globals #4492

@kaytwo

Description

@kaytwo

🚀 Feature

Expose markdown frontmatter in page globals.

Have you read the Contributing Guidelines on issues?

Yes

Motivation

I'd like to programmatically generate docs/pages based on custom metadata stored in the frontmatter of my docs. In my use case, I'm building a course website, where the docs are the descriptions of homeworks, labs, exams, etc, and I'd like to create a "calendar" page that reads release and due date metadata from the frontmatter of each of those pages. As of right now, only id, path, and sidebar are set in the plugin globals.

Pitch

While this is a very specific use case, I've typically seen frontmatter used in this way in other static site generators to create derivative pages that incorporate some or all of the important metadata from some subset of other pages.

I tried to implement something similar to this both using this approach as well as a standalone plugin that I wrote for this purpose (trying both setGlobalData and createData), but the issue is that the functionality is too tightly tied to the docs plugin itself to be easily factored out (and I couldn't figure out how to swizzle this part of @docusaurus/plugin-content-docs).

Implementation

The frontmatter can be propagated with this commit: kaytwo@ff408e1. I understand that this will increase the size of the globals which should be avoided, however this option could probably be gated behind a config option by replacing this line in docs.ts with:

    frontMatter : options.includeFrontmatter ? frontMatter : undefined

Metadata

Metadata

Assignees

No one assigned

    Labels

    domain: content pluginRelated to content plugin emitting metadata for theme consumptionfeatureThis is not a bug or issue with Docusausus, per se. It is a feature request for the future.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0