You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This remark plugin takes frontmatter content, and outputs it as JavaScript exports. Both YAML and
TOML frontmatter data are supported.
For example, given a file named example.mdx with the following contents:
---hello: frontmatter---
Rest of document
The following script:
import{readFile}from'node:fs/promises'import{compile}from'@mdx-js/mdx'importremarkFrontmatterfrom'remark-frontmatter'importremarkMdxFrontmatterfrom'remark-mdx-frontmatter'const{ value }=awaitcompile(awaitreadFile('example.mdx'),{jsx: true,remarkPlugins: [remarkFrontmatter,remarkMdxFrontmatter]})console.log(value)
Roughly yields:
exportconstfrontmatter={hello: 'frontmatter'}exportdefaultfunctionMDXContent(){return<p>Rest of document</p>}
default: The default value to export if no frontmatter data is found. (Default: undefined).
name: The identifier name of the variable the frontmatter data is assigned to. (Default:
frontmatter).
parsers: A mapping A mapping of node types to parsers. Each key represents a frontmatter node
type. The value is a function that accepts the frontmatter data as a string, and returns the
parsed data. By default yaml nodes will be parsed using yaml
and toml nodes using toml.
In addition it supports unist-util-mdx-defineoptions.
Compatibility
This project is compatible with Node.js 18 or greater.