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

Problems parsing frontmatter #15

Closed
sebald opened this issue May 10, 2024 · 9 comments
Closed

Problems parsing frontmatter #15

sebald opened this issue May 10, 2024 · 9 comments

Comments

@sebald
Copy link

sebald commented May 10, 2024

Hey! First of all thanks for continuing with this lib! 🥳

I tried to upgrade our project but ran into an issue. It seems like contentlayer2 has an issue with parsing frontmatter in .mdx files:

image

I tried to add the remark plugin like described here. But it seems like the issue is contentlayer internal. Looking at the code, contentlayer should be able to parse frontmatter already.

Is this a known issue or is it something on our side?

@fixtse
Copy link

fixtse commented May 11, 2024

Hi, I ran into the same issue when trying the updated packages.

image

@lloydrichards
Copy link

Had the same issue. The problem is apparent remark-gfm v3. By upgrading to v4 it solved the problem. (also make sure to remove contentlayer from node-modules and update imports to contentlayer2 since the first time I did this It was still using the first package 🤦 )

@timlrx
Copy link
Owner

timlrx commented May 12, 2024

contentlayer2 only supports remark / rehype packages using the latest unified js packages (v11+) e.g. remark-gfm@4.0.0. If you have upgraded the packages and it still throws an error, could you share a link to the repository?

@sebald
Copy link
Author

sebald commented May 14, 2024

@timlrx thanks for the quick reply. I just checked again and at least I hope i updated all the plugins (luckily typescript also warns if you forget!).

This is the repo/branch I am trying to update: https://github.com/marigold-ui/marigold/tree/contentlayer2

You find the next app under /docs. Here is the package.json and contentlayer config:

pnpm start start the next app.

@sebald
Copy link
Author

sebald commented May 14, 2024

If I can help investigate, let me know!

@sebald
Copy link
Author

sebald commented May 15, 2024

I investigated a bit more, it seems like our rehype plugin is the reason it breaks.

Specifically this code:

https://github.com/marigold-ui/marigold/blob/contentlayer2/docs/lib/mdx/rehype-component-demo.tsx#L108-L127

The unist-builder seems to break thinkgs 🤔

@sebald
Copy link
Author

sebald commented May 15, 2024

Since this is not an issue with contentlayer2 I will close this. Thanks for all the feedback and picking up the project 🥳

@lishaduck
Copy link
Contributor

It seems that the order matters.

This works:

    rehypePlugins: [
      [
        rehypePrettyCode,
        {
          ...DEFAULT_REHYPE_PRETTY_CODE_OPTIONS,
          theme: {
            dark: "github-dark",
            light: "github-light"
          },
          transformers: [
            // FIXME: Make it actually work. Currently it doesn't transform the code blocks.
            transformerTwoslash({
              explicitTrigger: true,
              renderer: rendererClassic()
            })
          ]
        } satisfies RehypePrettyCodeOptions
      ],
      [rehypeRaw, { passThrough: nodeTypes }],
      rehypeMdxCodeProps,
      rehypeSlug
    ]

This works, but incorrectly:

    rehypePlugins: [
      [rehypeRaw, { passThrough: nodeTypes }],
      [
        rehypePrettyCode,
        {
          ...DEFAULT_REHYPE_PRETTY_CODE_OPTIONS,
          theme: {
            dark: "github-dark",
            light: "github-light"
          },
          transformers: [
            // FIXME: Make it actually work. Currently it doesn't transform the code blocks.
            transformerTwoslash({
              explicitTrigger: true,
              renderer: rendererClassic()
            })
          ]
        } satisfies RehypePrettyCodeOptions
      ],
      rehypeSlug,
      rehypeMdxCodeProps
    ]

Any other config (haven't tried them all, but most of them) lead to the frontmatter error.

@i-am-the-slime
Copy link

i-am-the-slime commented Nov 3, 2024

I have the same problem. Does anybody know what to order how? Putting rehypeSlug last doesn't help in my case.

Update:
Looks like for me it's related to the getHighlighter option in rehypePrettyCode.

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

6 participants