Regression in frontmatter accessible to remark plugins in Astro 5 + Content Layer
Closed this issue · 1 comments
Astro Info
Astro v5.0.9
Node v18.20.3
System Linux (x64)
Package Manager npm
Output static
Adapter none
Integrations @astrojs/mdx
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
When using Astro v5 with Content Layer, there is a regression in the frontmatter accessible to remark plugins that is no longer the user-defined frontmatter but the frontmatter validated by the collection schema.
Using the following collection definition with a schema only allowing a title
property and using a transform to add an someOtherField
additional field:
const docs = defineCollection({
loader: glob({ pattern: "**/*.{md,mdx}", base: "./src/content/Docs" }),
schema: z
.object({
title: z.string(),
})
.transform((data) => ({
...data,
someOtherField: "Added by transform",
})),
});
And the following markdown file:
---
title: Test Mardown
foo: bar
---
Hello from Markdown!
A remark plugin accessing file.data.astro?.frontmatter
will get the following object:
{ title: 'Test Mardown', someOtherField: 'Added by transform' }
Using an MDX file with the same content or Astro v4, the object would be:
{ title: 'Test MDX', foo: 'bar' }
Additional notes:
- May need to run
npm run dev -- --force
in StackBlitz to see the logs - Here is a link to the same setup in Astro v4: https://stackblitz.com/edit/github-w2juvll6-fxyvazic?file=astro.config.mjs
What's the expected result?
The expected result should be the same as Astro v4 and be consistent between markdown and MDX files:
{ title: 'Test MDX', foo: 'bar' }
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-w2juvll6?file=astro.config.mjs
Participation
- I am willing to submit a pull request for this issue.
Thanks for the repro! Turns out it was a simple fix.