From c3dea3f0f921d9d8504d687a4a41ee0784acf354 Mon Sep 17 00:00:00 2001 From: sarahrainsberger Date: Mon, 26 Jan 2026 20:04:39 +0000 Subject: [PATCH 1/5] add new `retainBody` property for glob loader --- .../en/reference/content-loader-reference.mdx | 28 ++++++++++++++++++- .../en/reference/modules/astro-content.mdx | 2 ++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/content/docs/en/reference/content-loader-reference.mdx b/src/content/docs/en/reference/content-loader-reference.mdx index ac5bbb40a78b4..d8a7c049408ed 100644 --- a/src/content/docs/en/reference/content-loader-reference.mdx +++ b/src/content/docs/en/reference/content-loader-reference.mdx @@ -28,7 +28,7 @@ Astro provides two built-in loaders to help you fetch your collections. Both off The `glob()` loader creates entries from directories of files from anywhere on the filesystem. The supported file types are Markdown, MDX, Markdoc, JSON, YAML, and TOML files. -This loader accepts an object with the following properties: `pattern`, `base` (optional), and `generateId` (optional). +This loader accepts an object with the following properties: `pattern`, `base` (optional), `generateId` (optional), and `retainBody (optional)`. ```ts title="src/content.config.ts" {2,6,11,17-21} import { defineCollection } from 'astro:content'; @@ -44,6 +44,16 @@ const blog = defineCollection({ loader: glob({ pattern: "**/*.(md|mdx)", base: "./src/data/blog" }), schema: /* ... */ }); +const posts = defineCollection({ + /* Retrieve all Markdown files in your blog directory to prevent + * the raw body of content files from being stored in the data store. */ + loader: glob({ + pattern: '**/*.md', + base: './src/content/blog', + retainBody: false + }), + schema: /* ... */ +}); const authors = defineCollection({ /* Retrieve all JSON files in your authors directory while retaining * uppercase letters in the ID. */ @@ -91,6 +101,22 @@ A callback function that returns a unique string per entry in a collection. It a By default it uses [`github-slugger`](https://github.com/Flet/github-slugger) to generate a slug with [kebab-cased](https://developer.mozilla.org/en-US/docs/Glossary/Kebab_case) words. +#### `retainBody` + +

+ +**Type:** `boolean`
+**Default:** `true` +

+ +Whether or not to store the raw body of content files in the data store. + +Setting this property to `false` significantly reduces the deployed size of the data store and helps avoid hitting size limits for sites with very large collections. + +The rendered body will still be available in the `entry.rendered.html` property for markdown files, and the `entry.filePath` property will still point to the original file. For MDX collections this will dramatically reduce the size of the collection, as there will no longer be any body retained in the store. + +When `retainBody` is `false`, `entry.body` will be `undefined` instead of containing the raw file contents. + ### `file()` loader

diff --git a/src/content/docs/en/reference/modules/astro-content.mdx b/src/content/docs/en/reference/modules/astro-content.mdx index 42b6fa66f62d5..5dd646ed4bfef 100644 --- a/src/content/docs/en/reference/modules/astro-content.mdx +++ b/src/content/docs/en/reference/modules/astro-content.mdx @@ -278,6 +278,8 @@ An object of frontmatter properties inferred from your collection schema ([see ` A string containing the raw, uncompiled body of the Markdown or MDX document. +Note that if `retainBody: false` is set in a collection's `glob()` loader, this value will be `undefined` instead of containing the raw file contents. + ### `CollectionKey`

From 1195477424be03edbabe7c1e1afb52fda24832ba Mon Sep 17 00:00:00 2001 From: sarahrainsberger Date: Mon, 26 Jan 2026 20:17:21 +0000 Subject: [PATCH 2/5] update body reference with link and type --- src/content/docs/en/reference/modules/astro-content.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/content/docs/en/reference/modules/astro-content.mdx b/src/content/docs/en/reference/modules/astro-content.mdx index 5dd646ed4bfef..a8eb579f635fd 100644 --- a/src/content/docs/en/reference/modules/astro-content.mdx +++ b/src/content/docs/en/reference/modules/astro-content.mdx @@ -274,11 +274,11 @@ An object of frontmatter properties inferred from your collection schema ([see ` #### `body` -**Type:** `string` +**Type:** `string | undefined` A string containing the raw, uncompiled body of the Markdown or MDX document. -Note that if `retainBody: false` is set in a collection's `glob()` loader, this value will be `undefined` instead of containing the raw file contents. +Note that if [`retainBody`](/en/reference/content-loader-reference/#retainbody) is set to `false`, this value will be `undefined` instead of containing the raw file contents. ### `CollectionKey` From bf6222c678bfea33929c9bd18569cfc385ca99f8 Mon Sep 17 00:00:00 2001 From: sarahrainsberger Date: Mon, 26 Jan 2026 20:22:55 +0000 Subject: [PATCH 3/5] rework retainBody API entry --- src/content/docs/en/reference/content-loader-reference.mdx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/content/docs/en/reference/content-loader-reference.mdx b/src/content/docs/en/reference/content-loader-reference.mdx index d8a7c049408ed..6e6634f304784 100644 --- a/src/content/docs/en/reference/content-loader-reference.mdx +++ b/src/content/docs/en/reference/content-loader-reference.mdx @@ -107,15 +107,18 @@ By default it uses [`github-slugger`](https://github.com/Flet/github-slugger) to **Type:** `boolean`
**Default:** `true` +

Whether or not to store the raw body of content files in the data store. +When `retainBody` is `false`, [`entry.body`](/en/reference/modules/astro-content/#body) will be `undefined` instead of containing the raw file contents. + Setting this property to `false` significantly reduces the deployed size of the data store and helps avoid hitting size limits for sites with very large collections. -The rendered body will still be available in the `entry.rendered.html` property for markdown files, and the `entry.filePath` property will still point to the original file. For MDX collections this will dramatically reduce the size of the collection, as there will no longer be any body retained in the store. +For Markdown files, the rendered body will still be available in the `entry.rendered.html` property, and the `entry.filePath` property will still point to the original file. -When `retainBody` is `false`, `entry.body` will be `undefined` instead of containing the raw file contents. +For MDX collections, this will dramatically reduce the size of the collection, as there will no longer be any body retained in the store. ### `file()` loader From 6bbca3961ab5d1705fbc2479489ca953bee41989 Mon Sep 17 00:00:00 2001 From: sarahrainsberger Date: Mon, 26 Jan 2026 20:33:17 +0000 Subject: [PATCH 4/5] typo fix in code sample --- src/content/docs/en/reference/content-loader-reference.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/en/reference/content-loader-reference.mdx b/src/content/docs/en/reference/content-loader-reference.mdx index 6e6634f304784..8edc8fbd92cd1 100644 --- a/src/content/docs/en/reference/content-loader-reference.mdx +++ b/src/content/docs/en/reference/content-loader-reference.mdx @@ -45,7 +45,7 @@ const blog = defineCollection({ schema: /* ... */ }); const posts = defineCollection({ - /* Retrieve all Markdown files in your blog directory to prevent + /* Retrieve all Markdown files in your blog directory and prevent * the raw body of content files from being stored in the data store. */ loader: glob({ pattern: '**/*.md', From c4e6446c326a7fec3501178ee947161cf5c0e05b Mon Sep 17 00:00:00 2001 From: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com> Date: Mon, 26 Jan 2026 18:07:13 -0400 Subject: [PATCH 5/5] Apply suggestions from Armand review Co-authored-by: Armand Philippot --- .../docs/en/reference/content-loader-reference.mdx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/content/docs/en/reference/content-loader-reference.mdx b/src/content/docs/en/reference/content-loader-reference.mdx index 8edc8fbd92cd1..21e25a853cf7f 100644 --- a/src/content/docs/en/reference/content-loader-reference.mdx +++ b/src/content/docs/en/reference/content-loader-reference.mdx @@ -28,7 +28,7 @@ Astro provides two built-in loaders to help you fetch your collections. Both off The `glob()` loader creates entries from directories of files from anywhere on the filesystem. The supported file types are Markdown, MDX, Markdoc, JSON, YAML, and TOML files. -This loader accepts an object with the following properties: `pattern`, `base` (optional), `generateId` (optional), and `retainBody (optional)`. +This loader accepts an object with the following properties: `pattern`, `base` (optional), `generateId` (optional), and `retainBody` (optional). ```ts title="src/content.config.ts" {2,6,11,17-21} import { defineCollection } from 'astro:content'; @@ -44,12 +44,12 @@ const blog = defineCollection({ loader: glob({ pattern: "**/*.(md|mdx)", base: "./src/data/blog" }), schema: /* ... */ }); -const posts = defineCollection({ - /* Retrieve all Markdown files in your blog directory and prevent +const notes = defineCollection({ + /* Retrieve all Markdown files in your notes directory and prevent * the raw body of content files from being stored in the data store. */ loader: glob({ pattern: '**/*.md', - base: './src/content/blog', + base: './src/data/notes', retainBody: false }), schema: /* ... */ @@ -116,7 +116,7 @@ When `retainBody` is `false`, [`entry.body`](/en/reference/modules/astro-content Setting this property to `false` significantly reduces the deployed size of the data store and helps avoid hitting size limits for sites with very large collections. -For Markdown files, the rendered body will still be available in the `entry.rendered.html` property, and the `entry.filePath` property will still point to the original file. +For Markdown files, the rendered body will still be available in the [`entry.rendered.html` property](/en/reference/content-loader-reference/#rendered), and the [`entry.filePath` property](/en/reference/content-loader-reference/#filepath) will still point to the original file. For MDX collections, this will dramatically reduce the size of the collection, as there will no longer be any body retained in the store.