0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Fix MDX stack trace location with frontmatter (#11717)

This commit is contained in:
Bjorn Lu 2024-08-16 12:09:20 +08:00 committed by GitHub
parent 0109690c3b
commit 423614ebb6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/mdx': patch
---
Fixes stack trace location when failed to parse an MDX file with frontmatter

View file

@ -44,9 +44,10 @@ export function vitePluginMdx(mdxOptions: MdxOptions): Plugin {
async transform(code, id) {
if (!id.endsWith('.mdx')) return;
const { data: frontmatter, content: pageContent } = parseFrontmatter(code, id);
const { data: frontmatter, content: pageContent, matter } = parseFrontmatter(code, id);
const frontmatterLines = matter ? matter.match(/\n/g)?.join('') + '\n\n' : '';
const vfile = new VFile({ value: pageContent, path: id });
const vfile = new VFile({ value: frontmatterLines + pageContent, path: id });
// Ensure `data.astro` is available to all remark plugins
setVfileFrontmatter(vfile, frontmatter);