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(markdown): add support for TOML frontmatter in Markdown files. #12850

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

colinbate
Copy link

Changes

  • Changed the frontmatter parsing in @astrojs/markdown-remark to accept TOML format
  • Uses +++ as the delimiters
  • Doesn't require configuration
    • If the TOML delimiters are used it will parse as TOML
    • Otherwise defaults to YAML

Testing

Updated the frontmatter.test.js file, adding TOML equivalent tests alongside the existing YAML tests. Worth noting that the TOML test run notably faster, owing to the faster parsing

Docs

This is certainly something that should be documented. It allows you to use TOML based frontmatter, which is particularly useful if migrating from Hugo or another system that preferred TOML and you don't want to convert potentially thousands of files.

Works for content collections, or with standalone markdown files.

/cc @withastro/maintainers-docs for feedback!

@github-actions github-actions bot added the feat: markdown Related to Markdown (scope) label Dec 29, 2024
@colinbate colinbate changed the title Add support for TOML frontmatter in Markdown files. feat: add support for TOML frontmatter in Markdown files. Dec 31, 2024
@colinbate colinbate changed the title feat: add support for TOML frontmatter in Markdown files. feat(markdown): add support for TOML frontmatter in Markdown files. Dec 31, 2024
@ematipico
Copy link
Member

Why would we allow TOML frontmatter in .mdx files but not in .md files? It seems a missed opportunity

@colinbate
Copy link
Author

@ematipico Apologies, I didn't mean to imply this was only for MDX files. It works for both.

@sarah11918
Copy link
Member

sarah11918 commented Jan 7, 2025

This is certainly something that should be documented.

Yes, yes it should! 😄 But cool feature!

Please make sure to loop me in early on this for any docs work if the feature is accepted! Off the top of my head:

  • The Markdown Guidecan also include intro paragraph mentions "can also include frontmatter YAML" and we'd probably update to something like "frontmatter YAML (or TOML)"

  • on the same page, we mention that if you are importing Markdown you have access to frontmatter values on the frontmatter object. Is this also true when using TOML? If so, we should similarly have a brief mention here.

  • the Migrate from Hugo Guide mentions the difference in the available frontmatter formats will need to be updated. (And, any other "migrate from" where this is also the case!)

  • The MDX page seems pretty future-proof, mostly only mentioning "your Markdown frontmatter" instead of YAML explicitly except for again when describing exported properties available on the frontmatter object.

Note that I don't think we need e.g. a new section on "Using TOML for your frontmatter instead." I would simply update wherever we do reference YAML specifically as "the" frontmatter language. As long as the values in frontmatter are used the same way, whether YAML or TOML, there's no need to really call out one language or another.

@colinbate
Copy link
Author

Thanks Sarah, yes the values are there on the frontmatter property for imported Markdown.

And I agree that it doesn't need to be called out in a big way. Having it mentioned when frontmatter comes up is fine. I think as long as it surfaces when someone searches the docs for TOML then it will be a win.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: markdown Related to Markdown (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants