Skip to content
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

Empty Markdown frontmatter at build time #4429

Closed
1 task
PaulFarault opened this issue Aug 22, 2022 · 3 comments · Fixed by #5687
Closed
1 task

Empty Markdown frontmatter at build time #4429

PaulFarault opened this issue Aug 22, 2022 · 3 comments · Fixed by #5687
Assignees
Labels
- P2: nice to have Not breaking anything but nice to have (priority)

Comments

@PaulFarault
Copy link

What version of astro are you using?

1.0.6

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

npm

What operating system are you using?

Linux

Describe the Bug

When creating custom Markdown plugins (as in the doc):

  • Frontmatters are empty at build time.
  • It seems that Markdown files are processed twice at build time.

The output is correct at the end but the lack of frontmatter makes development harder.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-vgrdek?file=content%2Farticle1.md,content%2Farticle2.md,astro.config.ts,src%2Fplugins%2FremarkGetTitle.ts,src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.
@bholmesdev
Copy link
Contributor

bholmesdev commented Aug 22, 2022

Thanks for reporting @PaulFarault! So to be clear, the issue is "I expect my markdown frontmatter to be in file.data.astro.frontmatter, but it's an empty object instead?" Because that's a fair critique! Currently, we merge plugin frontmatter with your file's frontmatter at the end, without passing the file frontmatter to your plugins. I've been considering a change there too.

I'm also unable to see the "MD files are processed twice" issue when building in your stackblitz example. I see this output:

Before plugin: {}
After plugin: { title: 'Default title' }
Before plugin: {}
After plugin: { title: 'Default title' }

Since there are 2 markdown files, this should mean the files were processed only once? Lmk if I'm missing something here.

@bholmesdev bholmesdev self-assigned this Aug 22, 2022
@bholmesdev bholmesdev added the - P2: nice to have Not breaking anything but nice to have (priority) label Aug 22, 2022
@PaulFarault
Copy link
Author

Hi Ben! Thx for your answer!

I expect my markdown frontmatter to be in file.data.astro.frontmatter, but it's an empty object instead?

It's exactly that. Thanks for explaining me how it works. Would be nice to be able to have the frontmatter directly, for developping ease and even testing purposes!


Since there are 2 markdown files, this should mean the files were processed only once?

I got the same output as you but twice, which I interpreted as "MD files are processed twice". I may have misinterpreted tho.

Before plugin: {}
After plugin: { title: 'Default title' }
Before plugin: {}
After plugin: { title: 'Default title' }
Before plugin: {}
After plugin: { title: 'Default title' }
Before plugin: {}
After plugin: { title: 'Default title' }

@azan-n
Copy link

azan-n commented Nov 12, 2022

  • Frontmatters are empty at build time.

Was planning to make a 'Fake-CMS' remark plugin that would check the frontmatter for the properties I wanted to be present in every document. However, I recognized that this would be a bit of a hacky workaround. I'm glad I ran through Github issues because I found this beautifully detailed RFC:

https://github.com/withastro/rfcs/blob/content-schemas/proposals/0027-content-schemas.md

Kudos to @bholmesdev and the team, I am sorry if this goes off-topic, but I would be glad to contribute in whatever way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants