From 48b5851e07421e7d11327d53f78f7aad1dea85ea Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 28 Dec 2022 11:05:36 -0500 Subject: [PATCH 01/11] edit: make injecting frontmatter l3 heading --- src/pages/en/guides/markdown-content.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/en/guides/markdown-content.mdx b/src/pages/en/guides/markdown-content.mdx index 61accf8791acb..cdb38dad53a50 100644 --- a/src/pages/en/guides/markdown-content.mdx +++ b/src/pages/en/guides/markdown-content.mdx @@ -482,7 +482,7 @@ export default { } ``` -#### Example: Injecting frontmatter +### Injecting frontmatter You can add frontmatter properties to all of your Markdown and MDX files by using a [remark or rehype plugin](#markdown-plugins). From 89eda6cc58b04802af587f8b505839ca96748bb6 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 28 Dec 2022 11:09:43 -0500 Subject: [PATCH 02/11] new: add tip on `data.astro.frontmatter` default --- src/pages/en/guides/markdown-content.mdx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pages/en/guides/markdown-content.mdx b/src/pages/en/guides/markdown-content.mdx index cdb38dad53a50..efc2b73cae863 100644 --- a/src/pages/en/guides/markdown-content.mdx +++ b/src/pages/en/guides/markdown-content.mdx @@ -497,6 +497,12 @@ You can add frontmatter properties to all of your Markdown and MDX files by usin } ``` + :::tip + + + `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 based on other properties. + ::: + 2. Apply this plugin to your `markdown` or `mdx` integration config: ```js title="astro.config.mjs" "import { exampleRemarkPlugin } from './example-remark-plugin.mjs';" "remarkPlugins: [exampleRemarkPlugin]," From 3ca48829c932f2048393aa458e92fc12109288d5 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 28 Dec 2022 11:13:21 -0500 Subject: [PATCH 03/11] edit: Injecting -> Modifying programmatically --- src/pages/en/guides/markdown-content.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/en/guides/markdown-content.mdx b/src/pages/en/guides/markdown-content.mdx index efc2b73cae863..e266f8165d7f3 100644 --- a/src/pages/en/guides/markdown-content.mdx +++ b/src/pages/en/guides/markdown-content.mdx @@ -482,7 +482,7 @@ export default { } ``` -### Injecting frontmatter +### Modifying frontmatter programmatically You can add frontmatter properties to all of your Markdown and MDX files by using a [remark or rehype plugin](#markdown-plugins). From f9e4be4a025bceeee278c034f0f0d84b59323d01 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 28 Dec 2022 11:22:09 -0500 Subject: [PATCH 04/11] fix: injecting-frontmatter links --- src/pages/en/guides/content-collections.mdx | 4 ++-- src/pages/en/reference/api-reference.mdx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/en/guides/content-collections.mdx b/src/pages/en/guides/content-collections.mdx index fa3478c790520..12a65702a2385 100644 --- a/src/pages/en/guides/content-collections.mdx +++ b/src/pages/en/guides/content-collections.mdx @@ -390,9 +390,9 @@ const blogPosts = await getCollection('blog'); })} ``` -### Access injected frontmatter from `render()` +### Access modified frontmatter from `render()` -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()`: +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 `injectedFrontmatter` property from `render()`: ```astro "{ injectedFrontmatter }" --- diff --git a/src/pages/en/reference/api-reference.mdx b/src/pages/en/reference/api-reference.mdx index b881e43d89113..c36a4cb40c683 100644 --- a/src/pages/en/reference/api-reference.mdx +++ b/src/pages/en/reference/api-reference.mdx @@ -830,7 +830,7 @@ A function to compile a given Markdown or MDX document for rendering. This retur - `` - A component used to render the document's contents in an Astro file. - `headings` - A generated list of headings, [mirroring Astro's `getHeadings()` utility](/en/guides/markdown-content/#exported-properties) on Markdown and MDX imports. -- `injectedFrontmatter ` - An object of frontmatter [injected via remark or rehype plugins](/en/guides/markdown-content/#example-injecting-frontmatter). Set to type `any`. +- `injectedFrontmatter ` - An object of frontmatter [modified via remark or rehype plugins](/en/guides/markdown-content/#modifying-frontmatter-programmatically). Set to type `any`. ```astro --- From 2d1885b669e2c09ba3f292cb6b1fc02f12500218 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 28 Dec 2022 11:27:27 -0500 Subject: [PATCH 05/11] edit: injectedFrontmatter reference --- src/pages/en/reference/api-reference.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/en/reference/api-reference.mdx b/src/pages/en/reference/api-reference.mdx index c36a4cb40c683..b6e816b49a72b 100644 --- a/src/pages/en/reference/api-reference.mdx +++ b/src/pages/en/reference/api-reference.mdx @@ -830,7 +830,7 @@ A function to compile a given Markdown or MDX document for rendering. This retur - `` - A component used to render the document's contents in an Astro file. - `headings` - A generated list of headings, [mirroring Astro's `getHeadings()` utility](/en/guides/markdown-content/#exported-properties) on Markdown and MDX imports. -- `injectedFrontmatter ` - An object of frontmatter [modified via remark or rehype plugins](/en/guides/markdown-content/#modifying-frontmatter-programmatically). Set to type `any`. +- `injectedFrontmatter ` - The [modified frontmatter object](/en/guides/markdown-content/#modifying-frontmatter-programmatically) applied via remark or rehype plugins. Set to type `any`. ```astro --- From aee29958e42b2101c362395759361c8f27ad345e Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 28 Dec 2022 11:27:38 -0500 Subject: [PATCH 06/11] new: caution on remark / rehype plugin defaults --- src/pages/en/guides/content-collections.mdx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pages/en/guides/content-collections.mdx b/src/pages/en/guides/content-collections.mdx index 12a65702a2385..bdc069a5764cd 100644 --- a/src/pages/en/guides/content-collections.mdx +++ b/src/pages/en/guides/content-collections.mdx @@ -408,6 +408,10 @@ const blogPosts = await getCollection('blog'); 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. +:::caution +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`. +::: +
**🙋 Why don't `getCollection()` and `getEntry()` contain these values?** From 23674839b503cd1bf89a9fada74aab9bba136a9a Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 28 Dec 2022 11:37:46 -0500 Subject: [PATCH 07/11] edit: injectedFrontmatter -> remarkPluginFrontmatter --- src/pages/en/guides/content-collections.mdx | 14 +++++++------- src/pages/en/reference/api-reference.mdx | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/pages/en/guides/content-collections.mdx b/src/pages/en/guides/content-collections.mdx index bdc069a5764cd..f13641489604f 100644 --- a/src/pages/en/guides/content-collections.mdx +++ b/src/pages/en/guides/content-collections.mdx @@ -341,14 +341,14 @@ const { post } = Astro.props; ## Rendering entry content -Every collection entry includes a `render()` function that gives you access to the contents of the Markdown or MDX file. This includes a `` component for rendering the document body, as well as the document headings and injected frontmatter. +Every collection entry includes a `render()` function that gives you access to the contents of the Markdown or MDX file. This includes a `` component for rendering the document body, as well as the document headings and frontmatter modified via remark or rehype. ```astro {5} --- // src/pages/render-example.astro import { getEntry } from 'astro:content'; const entry = await getEntry('blog', 'post-1.md'); -const { Content, headings, injectedFrontmatter } = await entry.render(); +const { Content, headings, remarkPluginFrontmatter } = await entry.render(); --- ``` @@ -392,21 +392,21 @@ const blogPosts = await getCollection('blog'); ### Access modified frontmatter from `render()` -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 `injectedFrontmatter` property from `render()`: +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()`: -```astro "{ injectedFrontmatter }" +```astro "{ remarkPluginFrontmatter }" --- import { getCollection } from 'astro:content'; const blogPosts = await getCollection('blog'); --- {blogPosts.map(async (post) => { - const { injectedFrontmatter } = await post.render(); - return

{post.data.title} — {injectedFrontmatter.readingTime}

+ const { remarkPluginFrontmatter } = await post.render(); + return

{post.data.title} — {remarkPluginFrontmatter.readingTime}

})} ``` -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. +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. :::caution 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`. diff --git a/src/pages/en/reference/api-reference.mdx b/src/pages/en/reference/api-reference.mdx index b6e816b49a72b..ea8c8f6e31dd4 100644 --- a/src/pages/en/reference/api-reference.mdx +++ b/src/pages/en/reference/api-reference.mdx @@ -830,14 +830,14 @@ A function to compile a given Markdown or MDX document for rendering. This retur - `` - A component used to render the document's contents in an Astro file. - `headings` - A generated list of headings, [mirroring Astro's `getHeadings()` utility](/en/guides/markdown-content/#exported-properties) on Markdown and MDX imports. -- `injectedFrontmatter ` - The [modified frontmatter object](/en/guides/markdown-content/#modifying-frontmatter-programmatically) applied via remark or rehype plugins. Set to type `any`. +- `remarkPluginFrontmatter ` - The [modified frontmatter object](/en/guides/markdown-content/#modifying-frontmatter-programmatically) applied via remark or rehype plugins. Set to type `any`. ```astro --- import { getEntry } from 'astro:content'; const entry = await getEntry('blog', 'entry-1.md'); -const { Content, headings, injectedFrontmatter } = await entry.render(); +const { Content, headings, remarkPluginFrontmatter } = await entry.render(); --- ``` From 5026235b483f42789cac9abaed0c849b9a70a86d Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 28 Dec 2022 11:39:01 -0500 Subject: [PATCH 08/11] fix: Since import --- src/pages/de/guides/markdown-content.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/de/guides/markdown-content.mdx b/src/pages/de/guides/markdown-content.mdx index df7f2dcd4f028..6922fb7611eed 100644 --- a/src/pages/de/guides/markdown-content.mdx +++ b/src/pages/de/guides/markdown-content.mdx @@ -4,6 +4,8 @@ title: Markdown description: Verwendung von Markdown mit Astro --- +import Since from '~/components/Since.astro' + Markdown wird häufig verwendet, um textlastige Inhalte wie Blog-Beiträge und Dokumentationen zu erstellen. Astro bietet eine integrierte Unterstützung von Markdown mit einigen zusätzlichen Funktionen wie der Verwendung von JavaScript-Ausdrücken und Astro-Komponenten direkt in deinem Markdown. ## Markdown-Seiten From 4d4ade8e7bc449e241b8b7a7fdb7e75281e74cc3 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 28 Dec 2022 11:46:34 -0500 Subject: [PATCH 09/11] edit: how do you say "crap" in German --- src/pages/de/guides/markdown-content.mdx | 2 -- src/pages/en/guides/markdown-content.mdx | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pages/de/guides/markdown-content.mdx b/src/pages/de/guides/markdown-content.mdx index 6922fb7611eed..df7f2dcd4f028 100644 --- a/src/pages/de/guides/markdown-content.mdx +++ b/src/pages/de/guides/markdown-content.mdx @@ -4,8 +4,6 @@ title: Markdown description: Verwendung von Markdown mit Astro --- -import Since from '~/components/Since.astro' - Markdown wird häufig verwendet, um textlastige Inhalte wie Blog-Beiträge und Dokumentationen zu erstellen. Astro bietet eine integrierte Unterstützung von Markdown mit einigen zusätzlichen Funktionen wie der Verwendung von JavaScript-Ausdrücken und Astro-Komponenten direkt in deinem Markdown. ## Markdown-Seiten diff --git a/src/pages/en/guides/markdown-content.mdx b/src/pages/en/guides/markdown-content.mdx index e266f8165d7f3..f1e277bfa0476 100644 --- a/src/pages/en/guides/markdown-content.mdx +++ b/src/pages/en/guides/markdown-content.mdx @@ -3,9 +3,10 @@ layout: ~/layouts/MainLayout.astro title: Markdown & MDX description: Learn how to create content using Markdown or MDX with Astro i18nReady: true -setup: import Since from '~/components/Since.astro' --- +import Since from '~/components/Since.astro' + [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. 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. From 76748fa9ed263bba72e6c810803308e1e8945875 Mon Sep 17 00:00:00 2001 From: Ben Holmes Date: Wed, 28 Dec 2022 17:27:32 -0500 Subject: [PATCH 10/11] edit: remarkPluginFrontmatter rephrase Co-authored-by: Sarah Rainsberger --- src/pages/en/reference/api-reference.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/en/reference/api-reference.mdx b/src/pages/en/reference/api-reference.mdx index ea8c8f6e31dd4..0bc4aa7387f0b 100644 --- a/src/pages/en/reference/api-reference.mdx +++ b/src/pages/en/reference/api-reference.mdx @@ -830,7 +830,7 @@ A function to compile a given Markdown or MDX document for rendering. This retur - `` - A component used to render the document's contents in an Astro file. - `headings` - A generated list of headings, [mirroring Astro's `getHeadings()` utility](/en/guides/markdown-content/#exported-properties) on Markdown and MDX imports. -- `remarkPluginFrontmatter ` - The [modified frontmatter object](/en/guides/markdown-content/#modifying-frontmatter-programmatically) applied via remark or rehype plugins. Set to type `any`. +- `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`. ```astro --- From e61da4f72de19ecbe2577a2694599eb53f8af74a Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 28 Dec 2022 17:36:05 -0500 Subject: [PATCH 11/11] fix: "from this existing frontmatter" --- src/pages/en/guides/markdown-content.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/en/guides/markdown-content.mdx b/src/pages/en/guides/markdown-content.mdx index f1e277bfa0476..43e64f19c4dbc 100644 --- a/src/pages/en/guides/markdown-content.mdx +++ b/src/pages/en/guides/markdown-content.mdx @@ -501,7 +501,7 @@ You can add frontmatter properties to all of your Markdown and MDX files by usin :::tip - `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 based on other properties. + `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. ::: 2. Apply this plugin to your `markdown` or `mdx` integration config: