Skip to content

tmtk75/remark-next-mdx-frontmatter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

This module allows you to use Frontmatter with @next/mdx which doesn't officially support frontmatter.

This plugin only supports MDX v2.

To install

$ yarn add remark-next-mdx-frontmatter

Configure 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, { layoutPath: "../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...

You can give a layoutPath to each page in its frontmatter.

---
title: a page
layoutPath: ../../components/Page

About

Remark plugin to use frontmatter with @next/mdx

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published