You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pages/en/guides/content-collections.mdx
+12-8Lines changed: 12 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -341,14 +341,14 @@ const { post } = Astro.props;
341
341
342
342
## Rendering entry content
343
343
344
-
Every collection entry includes a `render()` function that gives you access to the contents of the Markdown or MDX file. This includes a `<Content />` component for rendering the document body, as well as the document headings and injected frontmatter.
344
+
Every collection entry includes a `render()` function that gives you access to the contents of the Markdown or MDX file. This includes a `<Content />` component for rendering the document body, as well as the document headings and frontmatter modified via remark or rehype.
Astro allows you to [inject frontmatter using remark or rehype plugins.](/en/guides/markdown-content/#example-injecting-frontmatter) You can access these values using the `injectedFrontmatter` property from `render()`:
395
+
Astro allows you to [modify frontmatter using remark or rehype plugins](/en/guides/markdown-content/#modifying-frontmatter-programmatically). You can access this modified frontmatter using the `remarkPluginFrontmatter` property from `render()`:
Assuming `readingTime` was injected ([see our reading time example](/en/guides/markdown-content/#example-calculate-reading-time)), it will be available on the `injectedFrontmatter` object.
409
+
Assuming `readingTime` was injected ([see our reading time example](/en/guides/markdown-content/#example-calculate-reading-time)), it will be available on the `remarkPluginFrontmatter` object.
410
+
411
+
:::caution
412
+
Remark and rehype plugins will have access to the _raw_ Markdown or MDX document frontmatter. This means frontmatter will not reflect any changes or defaults applied by your `schema`.
413
+
:::
410
414
411
415
<details>
412
416
<summary>**🙋 Why don't `getCollection()` and `getEntry()` contain these values?**</summary>
description: Learn how to create content using Markdown or MDX with Astro
5
5
i18nReady: true
6
-
setup: import Since from '~/components/Since.astro'
7
6
---
8
7
8
+
importSincefrom'~/components/Since.astro'
9
+
9
10
[Markdown](https://daringfireball.net/projects/markdown/) is commonly used to author text-heavy content like blog posts and documentation. Astro includes built-in support for standard Markdown files.
10
11
11
12
With the [@astrojs/mdx integration](/en/guides/integrations-guide/mdx/) installed, Astro also supports [MDX](https://mdxjs.com/) (`.mdx`) files which bring added features like support for JavaScript expressions and components in your Markdown content.
@@ -468,7 +469,7 @@ export default {
468
469
}
469
470
```
470
471
471
-
#### Example: Injecting frontmatter
472
+
###Modifying frontmatter programmatically
472
473
473
474
You can add frontmatter properties to all of your Markdown and MDX files by using a [remark or rehype plugin](#markdown-plugins).
474
475
@@ -483,6 +484,12 @@ You can add frontmatter properties to all of your Markdown and MDX files by usin
483
484
}
484
485
```
485
486
487
+
:::tip
488
+
<Sincev="2.0.0" />
489
+
490
+
`data.astro.frontmatter` contains all properties from a given Markdown or MDX document. This allows you to modify existing frontmatter properties, or compute new properties from this existing frontmatter.
491
+
:::
492
+
486
493
2. Apply this plugin to your `markdown` or `mdx` integration config:
487
494
488
495
```js title="astro.config.mjs" "import { exampleRemarkPlugin } from './example-remark-plugin.mjs';" "remarkPlugins: [exampleRemarkPlugin],"
Copy file name to clipboardExpand all lines: src/pages/en/reference/api-reference.mdx
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -830,14 +830,14 @@ A function to compile a given Markdown or MDX document for rendering. This retur
830
830
831
831
-`<Content />` - A component used to render the document's contents in an Astro file.
832
832
-`headings` - A generated list of headings, [mirroring Astro's `getHeadings()` utility](/en/guides/markdown-content/#exported-properties) on Markdown and MDX imports.
833
-
-`injectedFrontmatter` - An object of frontmatter [injected via remark or rehype plugins](/en/guides/markdown-content/#example-injecting-frontmatter). Set to type `any`.
833
+
-`remarkPluginFrontmatter` - The modified frontmatter object after any [remark or rehype plugins have been applied](/en/guides/markdown-content/#modifying-frontmatter-programmatically). Set to type `any`.
0 commit comments