#Which formats are accepted for frontmatter in md/mdx/mdoc files?

3 messages · Page 1 of 1 (latest)

inner haven
#

Is only yaml supported, or are there also other formats like toml, json... also supported? If so, does Astro provide a way to retrieve the frontmatter (whatever the type may be) from the file content? Ideally, this method should work before astro has built the files (i.e. during the astro:config:setup hook)

thorny kindleBOT
#

Hi @inner haven. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Astro supports frontmatter in Markdown (.md), MDX (.mdx), and Markdoc (.mdoc) files. The frontmatter is typically written in YAML format, as indicated in the Astro documentation (https://docs.astro.build/en/guides/markdown-content/#_top) and Starlight guide (https://starlight.astro.build/guides/authoring-content/#_top). There's no mention of support for other formats like TOML or JSON in the provided knowledge sources.

Astro provides a way to retrieve the frontmatter from the file content. For instance, in Markdown and MDX layouts, you can access frontmatter properties through Astro.props.frontmatter as shown in the Astro Basics guide (https://docs.astro.build/en/basics/layouts/#markdownmdx-layouts).

In addition, when loading Markdown files with Astro.glob(), the returned MarkdownInstance interface includes a frontmatter property that contains any data specified in the file's YAML frontmatter. You can optionally provide a type for the frontmatter variable using a TypeScript generic as shown in the Astro API reference (https://docs.astro.build/en/reference/api-reference/#markdown-files).

However, the provided knowledge sources do not specify whether this method works during the astro:config:setup hook or before Astro has built the files. For more specific details, you may want to refer to the Astro documentation (https://docs.astro.build/).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: