Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion src/content/docs/en/reference/content-loader-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 and 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. */
Expand Down Expand Up @@ -91,6 +101,25 @@ 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`

<p>

**Type:** `boolean`<br />
**Default:** `true`
<Since v="5.17.0" />
</p>

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.

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 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

<p>
Expand Down
4 changes: 3 additions & 1 deletion src/content/docs/en/reference/modules/astro-content.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,12 @@ 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`](/en/reference/content-loader-reference/#retainbody) is set to `false`, this value will be `undefined` instead of containing the raw file contents.

### `CollectionKey`

<p><Since v="3.1.0" /></p>
Expand Down