Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Regression in frontmatter accessible to remark plugins in Astro 5 + Content Layer #12778

Closed
1 task
HiDeoo opened this issue Dec 18, 2024 · 1 comment · Fixed by #12789
Closed
1 task

Regression in frontmatter accessible to remark plugins in Astro 5 + Content Layer #12778

HiDeoo opened this issue Dec 18, 2024 · 1 comment · Fixed by #12789
Assignees
Labels
feat: content layer Related to the Content Layer feature (scope) feat: markdown Related to Markdown (scope)

Comments

@HiDeoo
Copy link
Member

HiDeoo commented Dec 18, 2024

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:

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.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Dec 18, 2024
@ascorbic ascorbic added feat: markdown Related to Markdown (scope) feat: content layer Related to the Content Layer feature (scope) and removed needs triage Issue needs to be triaged labels Dec 19, 2024
@ascorbic ascorbic self-assigned this Dec 19, 2024
@ascorbic
Copy link
Contributor

Thanks for the repro! Turns out it was a simple fix.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
feat: content layer Related to the Content Layer feature (scope) feat: markdown Related to Markdown (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants