remark-next-mdx-frontmatter
v0.0.3
Published
This module allows you to use `Frontmatter` with [`@next/mdx`](https://nextjs.org/docs/advanced-features/using-mdx#nextmdx) which doesn't officially support frontmatter.
Downloads
11
Readme
README
This module allows you to use Frontmatter with @next/mdx which doesn't officially support frontmatter.
To install
$ yarn add remark-next-mdx-frontmatterConfigure your next.config.mjs. This module doesn't support next.config.js.
// next.config.mjs
import withMDXFm from "@next/mdx";
import remarkFm from "./lib/frontmatter.mjs";
const withMDX = withMDXFm({
extension: /\.mdx?$/,
options: {
remarkPlugins: [
[remarkFm, { path: "../components/Post" /* default path to layout component */ }]
]
},
});
const config = withMDX({ ...nextConfig });
export default config;Make a component at the path.
The attribute name is frontmatter.
// ../components/Post
type PostProps = {
children: JSX.Element;
frontmatter: {
[key: string]: number | string;
};
};
export default function Post({ children, frontmatter }: PostProps) {
return (
<article>
{frontmatter.title} written by {frontmatter.author}.
<section>{children}</section>
</article>
);
}Put a .mdx file with frontmatter.
// pages/hello.mdx
---
title: hello world
author: tmtk75
---
# Hello World
something...