-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
base: main
Are you sure you want to change the base?
Conversation
Why would we allow TOML frontmatter in |
@ematipico Apologies, I didn't mean to imply this was only for MDX files. It works for both. |
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:
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. |
Thanks Sarah, yes the values are there on the 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. |
🦋 Changeset detectedLatest commit: dd11713 The changes in this PR will be included in the next version bump. 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 |
The whole team is onboard with the new feature, however we need to have documentation in place. Once the documentation is there, we can merge it with the other minors |
OK, I'll add the updates to the docs, coordinating with @sarah11918 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving for docs! The docs PR is ready to go for the next release. 🥳
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me code-wise. We will update the changeset, and release the feature next week. Thank you @colinbate
.changeset/lazy-pandas-love.md
Outdated
Add support for TOML frontmatter in .md and .mdx files | ||
|
||
Uses the standard +++ as a delimiter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add support for TOML frontmatter in .md and .mdx files | |
Uses the standard +++ as a delimiter | |
Adds support for TOML frontmatter in `.md` and `.mdx` files | |
Astro 5.2 automatically identifies the format of your Markdown and MDX frontmatter based on the delimiter used. With `+++` as a delimiter (instead of the `---` YAML code fence), your frontmatter will automatically be recognized and parsed as [TOML](https://toml.io). | |
This is useful for adding existing content files with TOML frontmatter to your project from another framework such as Hugo. | |
TOML frontmatter can also be used with [content collections](https://docs.astro.build/guides/content-collections/), and files with different frontmatter languages can live together in the same project. | |
No configuration is required to use TOML frontmatter in your content files. Your delimiter will indicate your chosen frontmatter language: | |
```md | |
+++ | |
date = 2025-01-30 | |
title = 'Use TOML frontmatter in Astro!' | |
[params] | |
author = 'Colin Bate' | |
+++ | |
# Support for TOML frontmatter is here! | |
``` |
OK, just a rough draft suggestion, but for a minor, we can certainly hype the feature!! (Also, I made some assumptions pre-answering questions people might have, and snagged the code example from Hugo's frontmatter example, so adjust for accuracy.)
Something this length/style would totally be appropriate, I think. Feel free to play around with something like this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change the snippet like this:
[params]
- author = 'Colin Bate'
+author = 'Colin Bate'
Generally, people don't add spaces or tabs in TOML files. The rest is very good!
That was a fine description Sarah, thanks. I just tweaked the example a bit. |
Changes
@astrojs/markdown-remark
to accept TOML format+++
as the delimitersTesting
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 parsingDocs
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!