0

I set up nextjs13 with ts support and mdx according to the docs.

Now I want to import the frontmatter in one file which was exported from another file. Is that possible?

pages/post.mdx contains

export const meta = {
  title: "some meta",
}

pages/index.tsx contains

import post from './post.mdx';
console.log(post.meta);

Output:

undefined

Expected output:

{ title: "some meta" }
mxix
  • 3,539
  • 1
  • 16
  • 23
Page not found
  • 2,454
  • 2
  • 10
  • 19

2 Answers2

0

Found the solution, while stepping over a github comment:

Wrong:

import post from './post.mdx';
console.log(post.meta);

Correct:

import post, { meta } from './post.mdx';
console.log(meta);
Page not found
  • 2,454
  • 2
  • 10
  • 19
-1

I use front-matter, an NPM package.

Example:

import React from "react";
import fm from "front-matter";

export default function SomeComponent({ markdown }) {
  const data = fm(markdown);

  return <div>{JSON.stringify(data)}</div>;
}
Designly
  • 266
  • 1
  • 9