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

[MDX] Support YAML frontmatter #3995

Merged
merged 11 commits into from
Jul 21, 2022
Merged

[MDX] Support YAML frontmatter #3995

merged 11 commits into from
Jul 21, 2022

Conversation

bholmesdev
Copy link
Contributor

@bholmesdev bholmesdev commented Jul 20, 2022

Changes

  • Add 2 new remark plugins: remark-frontmatter, remark-mdx-frontmatter
    • Apply both plugins regardless of the user's remarkPlugins config. This is different from GFM and smartypants, which are each removed when configuring without extends. Let me know if this should be changed!
  • Apply frontmatter to frontmatter object export by default. This should make the Astro.glob experience fall in-line with plain markdown!
  • Add frontmatterOptions to config. This allows users to override remark-mdx-frontmatter defaults (ex. use a name other than the frontmatter object as the destination for YAML, including name: '' to avoid our frontmatter object).

Testing

  • Test frontmatter object
  • Test glob result
  • Test custom frontmatter name config

Docs

  • add variables and frontmatter explainers to show both use cases
  • add frontmatterOptions to README

@changeset-bot
Copy link

changeset-bot bot commented Jul 20, 2022

🦋 Changeset detected

Latest commit: 63e3074

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@astrojs/mdx Minor
astro Patch
@e2e/preact-component Patch
@e2e/react-component Patch
@e2e/solid-component Patch
@e2e/svelte-component Patch
@e2e/astro-component Patch
@e2e/error-react-spectrum Patch
@e2e/error-sass Patch
@e2e/errors Patch
@e2e/lit-component Patch
@e2e/e2e-tailwindcss Patch
@e2e/ts-resolution Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope) labels Jul 20, 2022
@@ -59,7 +59,7 @@ function shouldSkipDraft(pageModule: ComponentInstance, astroConfig: AstroConfig
!astroConfig.markdown.drafts &&
// This is a draft post
'frontmatter' in pageModule &&
(pageModule as any).frontmatter.draft === true
(pageModule as any).frontmatter?.draft === true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remark-mdx-frontmatter applies export const frontmatter = undefined when no frontmatter is present. This handles that case!

Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! Is there any particular reason to expose the RemarkMdxFrontmatterOptions to the user? If it's only to change frontmatter, I feel like we probably don't need to expose it? I don't think we've ever gotten any requests to configure this setting for .md files.

@bholmesdev
Copy link
Contributor Author

bholmesdev commented Jul 20, 2022

@natemoo-re Added some use cases to the README! I'd argue this is more necessary for MDX, since all exports are at the root level by default. I could see people wanting to put YAML frontmatter at the root as well 🤷
https://github.com/withastro/astro/pull/3995/files#diff-f8b3ea982e3a2f14022902aeaefe786a2477d13f756d4679f70a249b2bacfd7bR204-R206

@bholmesdev bholmesdev merged commit b2b367c into main Jul 21, 2022
@bholmesdev bholmesdev deleted the feat/mdx-frontmatter branch July 21, 2022 01:34
@astrobot-houston astrobot-houston mentioned this pull request Jul 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants