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

feat: siteConfig.markdown.parseFrontMatter hook #9624

Merged
merged 18 commits into from Dec 16, 2023
Merged

Conversation

slorber
Copy link
Collaborator

@slorber slorber commented Dec 8, 2023

Motivation

The ability to provide your own markdown front matter parsing logic unlocks many fancy use cases.

Fix #5568

Example

export default {
  markdown: {
    parseFrontMatter: async (params) => {
      // Reuse the default parser
      const result = await params.defaultParseFrontMatter(params);

      // Process front matter description placeholders
      result.frontMatter.description =
        result.frontMatter.description?.replaceAll('{{MY_VAR}}', 'MY_VALUE');

      // Create your own front matter shortcut
      if (result.frontMatter.i_do_not_want_docs_pagination) {
        result.frontMatter.pagination_prev = null;
        result.frontMatter.pagination_next = null;
      }

      // Rename an unsupported front matter coming from another system
      if (result.frontMatter.cms_seo_summary) {
        result.frontMatter.description = result.frontMatter.cms_seo_summary;
        delete result.frontMatter.cms_seo_summary;
      }

      return result;
    },
  },
}

Test Plan

CI + preview + dogfooding

Test links

https://deploy-preview-9624--docusaurus-2.netlify.app/

Test page that gets unlisted thanks to parseFrontMatter:
https://deploy-preview-9624--docusaurus-2.netlify.app/tests/docs/tests/visibility/force-unlisted

Docs:

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Dec 8, 2023
Copy link

netlify bot commented Dec 8, 2023

[V2]

Name Link
🔨 Latest commit 516016a
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/657cf59067c6180008283958
😎 Deploy Preview https://deploy-preview-9624--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

github-actions bot commented Dec 8, 2023

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟠 71 🟢 98 🟢 100 🟢 100 🟠 89 Report
/docs/installation 🟠 87 🟢 98 🟢 100 🟢 100 🟠 89 Report
/docs/category/getting-started 🟠 76 🟢 100 🟢 100 🟢 90 🟠 89 Report
/blog 🟠 74 🟢 100 🟢 100 🟢 90 🟠 89 Report
/blog/preparing-your-site-for-docusaurus-v3 🟠 64 🟢 97 🟢 100 🟢 100 🟠 89 Report
/blog/tags/release 🟠 74 🟢 100 🟢 100 🟠 80 🟠 89 Report
/blog/tags 🟠 77 🟢 100 🟢 100 🟢 90 🟠 89 Report

@slorber slorber added the pr: new feature This PR adds a new API or behavior. label Dec 8, 2023
Copy link

github-actions bot commented Dec 8, 2023

Size Change: +712 B (0%)

Total Size: 926 kB

Filename Size Change
website/.docusaurus/globalData.json 59.2 kB +220 B (0%)
website/build/assets/js/main.********.js 716 kB +492 B (0%)
ℹ️ View Unchanged
Filename Size
website/build/assets/css/styles.********.css 114 kB
website/build/index.html 37.6 kB

compressed-size-action

@slorber slorber added the Argos Add this label to run UI visual regression tests. See argos.yml GH action. label Dec 16, 2023
Copy link

argos-ci bot commented Dec 16, 2023

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) 🧿 Changes detected (Review) 125 changes Jan 5, 2024, 6:57 PM

@slorber slorber merged commit affca7a into main Dec 16, 2023
3 of 4 checks passed
@slorber slorber deleted the slorber/createFrontMatter branch December 16, 2023 01:50
@slorber slorber added the to backport This PR is planned to be backported to a stable version of Docusaurus label Dec 16, 2023
@slorber slorber removed the to backport This PR is planned to be backported to a stable version of Docusaurus label Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Argos Add this label to run UI visual regression tests. See argos.yml GH action. backported This PR has been backported to a stable version of Docusaurus CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docs / blog / pages: createFrontMatter callback to transform front matter
2 participants