-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
make parsed md/mdx frontmatter available to plugins #5099
Comments
@bholmesdev is this possible? |
here you could use |
@matthewp It should be, and I've proposed a couple solutions in our discord One suggestion was to add user frontmatter to the i.e. if a user has this: ---
title: My blog post
--- And your plugin specifies this: ...
data.astro.frontmatter.title = "My title override"
Another non- breaking option would be to add a readonly version of the user's frontmatter as a separate property. Something like Personally, I've been setting this aside as a 2.0 concern to avoid over-complicating the API, and also investigating how our Content Schemas RFCs can address this in a more predictable way. Though if |
I am very much in favor to give injectedFrontmatter the possibility to override pageFrontmatter, but then, also give the injecting plugin the pageFrontmatter as input, so the plugin can responsibly choose, whether it wants to override something. In the above example, it would be as easy as using Nullish coalescing assignment data.astro.frontmatter.title ??= "My title override" One of my archetypical use cases is 'relative images in frontmatter': My users can reference images in frontmatter, and they may use relative paths. My plugin would take care of resolving those paths, so I do not have to worry about that in the code of my website. Currently I have 2 choices, I can either write the resolved paths into a second frontmatter property (leaving me with the trouble to always remember to use frontmatter.author.resolvedAvatar) or I can do the resolution of frontmatter paths in my markdown layout (which I opted for now, but that separates resolution of paths in the markdown from the resolution in frontmatter, which is also ugly for maintenance reasons).
I could create a PR, that would prefill frontmatter with pageFrontmatter in the VFile, that is passed to plugins and then we would probably not need a merge afterwards anymore (but that we could discuss). |
@christian-hackyourshack Very much in favor of that change! Still, for the reasons I outlined in my previous comment, this would be a breaking change we'd have to delay to a major 2.0 release. Partially why I wanted to explore short term solutions like a separate readonly |
What version of
astro
are you using?1.5.0
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
currently,
remark
/rehype
plugins are only allowed to add additional fields tovfile.data.astro.frontmatter
, however the parsed frontmatter from markdown/mdx sources files is not made available to plugins (i.e.vfile.data.astro.frontmatter
is passed as an empty object).Link to Minimal Reproducible Example
https://github.com/stefanprobst/issue-astro-md-frontmatter/blob/main/astro.config.mjs
Participation
The text was updated successfully, but these errors were encountered: