-
Notifications
You must be signed in to change notification settings - Fork 145
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
Export alternative to compileMDX
for RSC which only returns frontmatter
#424
Comments
I will share soon a forked and updated version of Edit: Here is the utility function to get the frontmatter without compiling the content Utility
|
Running into the same issue, but reluctant to add an alternative package for the time being. Is there any plan for next-mdx-remote to support loading frontmatter only? |
I ended up doing it myself, which was pretty simple using import fs from 'fs/promises'
import path from 'path'
import { VFile } from 'vfile'
import { matter } from 'vfile-matter'
async function parseMdx(filepath: string) {
const source = await fs.readFile(filepath, {
encoding: 'utf8',
flag: 'r',
})
const vfile = new VFile(source)
const slug = path.basename(filepath, '.mdx')
const meta = matter(vfile, { strip: true }).data.matter
return {
meta,
slug,
source: String(vfile),
}
} |
Hi @Svish, apart from getting slug of a file, One beneficial of The subpath "next-mdx-remote-client/utils" is isolated from other features of the package and it does cost minimum. So anyone can use My additional advice is that let |
Maybe that function should be documented better then? Either way, I no longer need it, hehe. Type parameter has no relevance for me because in my actual code I actually use a zod schema to parse and validate the frontmatter. That code is not my actual code, it's just the boiled down stuff relevant here. |
I have successfully created a blog using the new
next-mdx-remote/rsc
API, and it works pretty great.My only issue so far, is that gathering the frontmatter from all the blog posts (for indexes, lists, etc) using
compileMDX
is rather slow.It would be great if there was an alternative export which worked the same as
compileMDX
, but only returned the frontmatter and (importantly) skipped all the actual MDX work.I'm guessing I could use a different dependency to just strip out that frontmatter myself, but would be great if it could be a builtin export from this library so I can trust that it's done the same way in both cases. That is, the frontmatter returned from
compileMDX
andextractFrontmatter
(or whatever) should always be the same and use the same code behind.The text was updated successfully, but these errors were encountered: