Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass both frontmatter and body field for md and mdx content #106

Closed
timlrx opened this issue Feb 2, 2022 · 1 comment
Closed

Pass both frontmatter and body field for md and mdx content #106

timlrx opened this issue Feb 2, 2022 · 1 comment

Comments

@timlrx
Copy link

timlrx commented Feb 2, 2022

It seems that contentlayer parses out the fields from md and mdx content and only the body of the content is subsequently passed to markdownToHtml or bundleMDX.

This causes an issue with downstream plugins that rely on the frontmatter properties of the document. Could we pass the entire md/mdx file as the body? Thanks.

For example the following mdx document:

---
title: Sample .md file
date: '2016-03-08'
---

A sample post with markdown.

produces the following mdast from contentlayer (logged at the first task of remarkPlugins):

{
  type: 'root',
  children: [
    { type: 'paragraph', children: [Array], position: [Object] }
  ],
  position: {
    start: { line: 1, column: 1, offset: 0 },
    end: { line: 3, column: 1, offset: 30 }
  }
}

Using mdx-bundler directly gives the following output:

{
  type: 'root',
  children: [
    { type: 'mdxjsEsm', value: '', data: [Object] },
    {
      type: 'yaml',
      value: "title: Sample .md file\ndate: '2016-03-08'",
      position: [Object]
    },
    { type: 'paragraph', children: [Array], position: [Object] }
  ],
  position: {
    start: { line: 1, column: 1, offset: 0 },
    end: { line: 7, column: 1, offset: 89 }
  }
}
@schickling
Copy link
Collaborator

This problem should now be addressed with version 0.1.0. Contentlayer now passes the full raw document string (incl. the frontmatter) to the MD or MDX pipeline.

If you're running into problems, please let me know. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants