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

Can't modify Markdown frontmatter from remark plugin #3737

Closed
1 task
rgov opened this issue Jul 16, 2023 · 4 comments
Closed
1 task

Can't modify Markdown frontmatter from remark plugin #3737

rgov opened this issue Jul 16, 2023 · 4 comments
Labels
good first issue Good for newcomers help wanted Issues looking for someone to run with them! improve or update documentation Enhance / update existing documentation (e.g. add example, improve description, update for changes) low effort

Comments

@rgov
Copy link
Contributor

rgov commented Jul 16, 2023

What version of astro are you using?

2.8.3

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

none

What package manager are you using?

nom

What operating system are you using?

macOS Ventura

What browser are you using?

Safari

Describe the Bug

The example given for modifying Markdown frontmatter programmatically doesn't seem to work.

Following exactly that example, I can see (with console.log()) that my plugin is being called. But in one of my .astro files I inspect the data objects for each post, and the inserted field is not present.

(Question: Is there any difference between the markdown and mdx sections of the config file? The documentation seems ambivalent about which to use. I've tried both.)

What's the expected result?

The example should add the customProperty to the front matter.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-klm8sa?file=example-remark-plugin.mjs

Participation

  • I am willing to submit a pull request for this issue.
@rgov rgov changed the title Can't modify Markdown front matter data from plugin Can't modify Markdown frontmatter from plugin Jul 16, 2023
@rgov rgov changed the title Can't modify Markdown frontmatter from plugin Can't modify Markdown frontmatter from remark plugin Jul 16, 2023
@rgov
Copy link
Contributor Author

rgov commented Jul 16, 2023

withastro/astro#5687 says,

To reflect this, the injectedFrontmatter property has been renamed to remarkPluginFrontmatter. This should clarify this plugin is still separate from the data export Content Collections expose today. We also expect remarkPluginFrontmatter to be deprecated once schemas can compute frontmatter based on file contents.

The renaming does not clarify things for me. What else does modifying the frontmatter affect? I suppose it could change an MDX file's { frontmatter.customProperty }, but I'm not sure what the use case would be.


Edit: I see, this separate part of the documentation is more clarifying. The plugin only runs at render time.

@Princesseuh Princesseuh transferred this issue from withastro/astro Jul 17, 2023
@Princesseuh
Copy link
Member

Transferring to docs since it seems like this was mostly a misunderstanding of the docs regarding when remark plugins affect the frontmatter

@delucis delucis added the improve or update documentation Enhance / update existing documentation (e.g. add example, improve description, update for changes) label Jul 27, 2023
@delucis
Copy link
Member

delucis commented Jul 27, 2023

Thanks for transferring @Princesseuh.

The guidance in the Markdown guide works well when NOT using content collections, but we should add a link to the content collections version to make the difference clearer.

@delucis delucis added good first issue Good for newcomers help wanted Issues looking for someone to run with them! low effort labels Jul 27, 2023
@TheOtterlord
Copy link
Member

Fixed in #3988

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Issues looking for someone to run with them! improve or update documentation Enhance / update existing documentation (e.g. add example, improve description, update for changes) low effort
Projects
None yet
Development

No branches or pull requests

4 participants