Convert frontmatter to MDX exports
mainThe remark-mdx-frontmatter plugin converts YAML or TOML frontmatter into JavaScript export statements within an MDX document. This allows you to access your metadata as variables within your MDX components or application code.
import { readFile } from 'node:fs/promises'
import { compile } from '@mdx-js/mdx'
import remarkFrontmatter from 'remark-frontmatter'
import remarkMdxFrontmatter from 'remark-mdx-frontmatter'
const { value } = await compile(await readFile('example.mdx'), {
jsx: true,
remarkPlugins: [remarkFrontmatter, remarkMdxFrontmatter]
})
console.log(value)