#Help with accessing frontmatter added with remark
2 messages · Page 1 of 1 (latest)
It seems you're having issues with accessing the frontmatter after migrating to Astro content collections. In Astro v2.0, remark and rehype plugins have access to user frontmatter via frontmatter injection, which allows plugin authors to modify a user's existing frontmatter or compute new properties based on other properties (source (https://docs.astro.build/en/guides/upgrade-to/v2#changed-plugin-access-to-frontmatter)).
To access the modified frontmatter inside a content entry, you can use the remarkPluginFrontmatter property returned from render() (source (https://docs.astro.build/en/guides/content-collections#modifying-frontmatter-with-remark)):
---
import { getEntryBySlug } from 'astro:content';
const blogPost = await getEntryBySlug('blog', 'post-1');
const { remarkPluginFrontmatter } = await blogPost.render();
---
<!--
This example assumes `readingTime` was injected by a remark plugin.
See our "reading time" example for more details:
https://docs.astro.build/en/guides/markdown-content/#example-calculate-reading-time
-->
<p>{blogPost.data.title} — {remarkPluginFrontmatter.readingTime}</p>
However, using this approach is not recommended, as it is handled separately from your type-safe schema and will not reflect any changes or defaults applied through Astro. Use it at your own risk (source (https://docs.astro.build/en/guides/content-collections#modifying-frontmatter-with-remark)).