mirror of
https://github.com/withastro/astro.git
synced 2025-01-06 22:10:10 -05:00
Fix MDX stack trace location with frontmatter (#11717)
This commit is contained in:
parent
0109690c3b
commit
423614ebb6
2 changed files with 8 additions and 2 deletions
5
.changeset/mighty-trees-teach.md
Normal file
5
.changeset/mighty-trees-teach.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@astrojs/mdx': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixes stack trace location when failed to parse an MDX file with frontmatter
|
|
@ -44,9 +44,10 @@ export function vitePluginMdx(mdxOptions: MdxOptions): Plugin {
|
||||||
async transform(code, id) {
|
async transform(code, id) {
|
||||||
if (!id.endsWith('.mdx')) return;
|
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
|
// Ensure `data.astro` is available to all remark plugins
|
||||||
setVfileFrontmatter(vfile, frontmatter);
|
setVfileFrontmatter(vfile, frontmatter);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue