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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs / blog / pages: createFrontMatter callback to transform front matter #5568

Closed
christianvoigt opened this issue Sep 13, 2021 · 6 comments 路 Fixed by #9624
Closed

Docs / blog / pages: createFrontMatter callback to transform front matter #5568

christianvoigt opened this issue Sep 13, 2021 · 6 comments 路 Fixed by #9624
Assignees
Labels
apprentice Issues that are good candidates to be handled by a Docusaurus apprentice / trainee domain: content plugin Related to content plugin emitting metadata for theme consumption feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.
Milestone

Comments

@christianvoigt
Copy link

馃挜 Proposal

We have a collection of Markdown articles that we want to use a) as a data source for a Docusaurus site and b) as a data source for Pandoc to generate pdfs from them via Latex (these will be printed out and used in schools and universities).

Pandoc expects multiple authors to be listed in the frontmatter "author" field, while Docusaurus expects them to be listed in the "authors" field. It would be great if the blog plugin would either also accept multiple authors in the "author" field or (even better) offer a method to provide a custom metadata provider that can override the default behaviour of the blog plugin and create the blog metadata from the Markdown frontmatter. Maybe this is already possible, but I could not find a way in the docs or by taking a quick look at the source code.

Keeping Markdown source files for blog articles decoupled from any specific publishing pipeline does make sense in general and such a customization option in Docusaurus would make it much easier to do so.

@christianvoigt christianvoigt added status: needs triage This issue has not been triaged by maintainers proposal This issue is a proposal, usually non-trivial change labels Sep 13, 2021
@slorber
Copy link
Collaborator

slorber commented Sep 21, 2021

Agree, and I plan to add a hool like createFrontMatter allowing you to transform existing frontmatter from Pandoc schema to Docusaurus schema

This has been discussed in a few issues already (like #5478 (comment)) and I plan to implement this soon

@Josh-Cena Josh-Cena changed the title blog plugin: accept multiple authors in "author" frontmatter field (not only in "authors") or let me transform frontmatter into metadata Docs / blog / pages: createFrontMatter callback to transform front matter Oct 30, 2021
@Josh-Cena Josh-Cena added feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. and removed status: needs triage This issue has not been triaged by maintainers proposal This issue is a proposal, usually non-trivial change labels Oct 30, 2021
@Josh-Cena Josh-Cena self-assigned this Nov 10, 2021
@slorber
Copy link
Collaborator

slorber commented Nov 10, 2021

@Josh-Cena indeed this issue is important as it solves multiple use-cases in a generic way. It's not my main focus currently as it doesn't really block 2.0, so if you want to work on it 馃憤

Maybe we could use a parseFrontMatter hook instead:

  • users can strip a copyright at the top (recently requested)
  • users can use a faster parsing lib or whatever they want with more flexibility

My proposal:

const config = {
  // we'll later add more markdown-related global configs
  markdown: {
    parseFrontMatter: async ({
      plugin,
      content, // markdown file content string
      defaultParseFrontMatter // reuse existing utils parseFrontMatter
    }) => {
      const contentWithoutCopyright = removeCopyright(content);
      const { frontMatter, markdown } =
        plugin.name === "docs" && plugin.id === "ios"
          ? await customiOSParser(contentWithoutCopyright)
          : defaultParseFrontMatter(contentWithoutCopyright);
      return {
        frontMatter: customFrontMatterNormalization(frontMatter),
        markdown
      };
    }
  }
};

We should avoid adding a parseFrontMatter option to plugins options for now, as a global API may be good enough.

Does it make sense?

@Josh-Cena
Copy link
Collaborator

Yes, this makes sense馃憤 And will probably be the first step towards #4625

@slorber
Copy link
Collaborator

slorber commented Aug 24, 2022

Another use-case to disable frontmatter draft: #7995

@slorber
Copy link
Collaborator

slorber commented Oct 12, 2022

Use-case: reading frontmatter of other locales (mostly the default locale). IE when building fr, access both en+fr frontMatter

#8197

@slorber
Copy link
Collaborator

slorber commented Jan 18, 2023

Use-case: process frontMatter.description to replace variables/placeholders with real value.

#395 (comment)

image

@slorber slorber added the apprentice Issues that are good candidates to be handled by a Docusaurus apprentice / trainee label Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apprentice Issues that are good candidates to be handled by a Docusaurus apprentice / trainee domain: content plugin Related to content plugin emitting metadata for theme consumption feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.
Projects
None yet
3 participants