How to expose meta/frontmatter in MDXProvider? #2037
-
Hello! Me again. In the context of Next.js -- say I have some mdx files which contain metadata, either in the form of frontmatter or an
The
Thanks! <3 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Things exported from a file, are not passed to the component. If you want, you can access exported things from outside MDX already: import Content, {meta} from './path/to/file.mdx'
console.log(meta) You can use this information: import Content, {meta} from './path/to/file.mdx'
import Layout from './path/to/file.jsx'
<Layout>
<h1>{meta.title}</h1>
<Content />
</Layout> Or, as you’re doing in your last example, make your own small wrapper. |
Beta Was this translation helpful? Give feedback.
-
Hey @wooorm / @ChristianMurphy I have created a plugin specifically for this problem. It replaces the remark-mdx-frontmatter plugin and inserts an https://github.com/omidantilong/remark-mdx-next Cheers |
Beta Was this translation helpful? Give feedback.
Hey @wooorm / @ChristianMurphy
I have created a plugin specifically for this problem. It replaces the remark-mdx-frontmatter plugin and inserts an
export function getStaticProps() {}
in the compiled mdx with all your frontmatter in.https://github.com/omidantilong/remark-mdx-next
Cheers