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

can't get the frontmatter inform via the string source, but can get the frontmatter when read from the 'mdx' files #475

Open
BertramYe opened this issue Sep 24, 2024 · 1 comment

Comments

@BertramYe
Copy link

Describe the bug

failed to get the fontmatter via the code here below with the latest version : [email protected] and also set the parseFrontmatter: true

import { compileMDX } from 'next-mdx-remote/rsc'

const BlogDetailPage = async() => {
    const source = `
        ---
            title: Bertram's Blogs
            author: Bertram
        ---
    
        # Welcome to my MDX page!
    
        This is some **bold** and _italics_ text.
        
        This is a list in markdown:
        - One
        - Two
        - Three
    `
   const {frontmatter,content }  = await compileMDX<{ title: string,author:string }>({
        source:source,
        options: { parseFrontmatter: true },
    })
    console.log('frontmatter',frontmatter) // the frontmatter result is {}
    return (
        <div>
            {content}
        </div>
    )
}
export default BlogDetailPage

but when I put the source in to a mdx files and then I read from the mdx files with the same codes like below here, I can get the frontmatter correctly

import { compileMDX } from 'next-mdx-remote/rsc'
import fs from 'fs'
import path from 'path'


const BlogDetailPage = async() => {
     const data = fs.readFileSync(path.join(process.cwd(),'mdxfiles/test.mdx')) // test.mdx has the same code of the `souce` above 
   const {frontmatter,content }  = await compileMDX<{ title: string,author:string }>({
        source:source,
        options: { parseFrontmatter: true },
    })
    console.log('frontmatter',frontmatter) // the frontmatter result is : frontmatter: { title: "Bertram's Blogs", author: 'Bertram' })
    return (
        <div>
            {content}
        </div>
    )
}
export default BlogDetailPage

Reproduction

you can try on you self side

next-mdx-remote version

v 5.0.0 and also I have tried with the version next-mdx-remote@canary the result is the same

@talatkuyuk
Copy link

You are doing wrong in indentations. Remove all indentations from the string of source.

const BlogDetailPage = async() => {
    const source = `
---
title: Bertram's Blogs
author: Bertram
---
    
# Welcome to my MDX page!
    
This is some **bold** and _italics_ text.
        
This is a list in markdown:
- One
- Two
- Three
`
    // ...
}

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

No branches or pull requests

2 participants