From e6638d6f757d35be2e2c63947bde6e0cdad48dfd Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Sat, 8 Nov 2025 17:04:49 +0100 Subject: [PATCH 1/4] fix(v6): use valid code snippets for content collections --- .../docs/en/guides/content-collections.mdx | 54 ++++++++++++------- .../en/reference/content-loader-reference.mdx | 53 +++++++++--------- .../en/reference/modules/astro-content.mdx | 29 +++++----- 3 files changed, 80 insertions(+), 56 deletions(-) diff --git a/src/content/docs/en/guides/content-collections.mdx b/src/content/docs/en/guides/content-collections.mdx index e972bb5f78acc..0b1ff655385a7 100644 --- a/src/content/docs/en/guides/content-collections.mdx +++ b/src/content/docs/en/guides/content-collections.mdx @@ -166,8 +166,8 @@ The [`glob()` loader](/en/reference/content-loader-reference/#glob-loader) fetch This loader accepts a `pattern` of entry files to match using glob patterns supported by [micromatch](https://github.com/micromatch/micromatch#matching-features), and a base file path of where your files are located. Each entry's `id` will be automatically generated from its file name. ```ts title="src/content.config.ts" {5} -import { defineCollection, z } from 'astro:content'; -import { glob, file } from 'astro/loaders'; +import { defineCollection } from 'astro:content'; +import { glob } from 'astro/loaders'; const blog = defineCollection({ loader: glob({ pattern: "**/*.md", base: "./src/data/blog" }), @@ -183,7 +183,7 @@ The [`file()` loader](/en/reference/content-loader-reference/#file-loader) fetch It accepts a `base` file path to your file and optionally a [`parser` function](#parser-function) for data files it cannot parse automatically. Use this loader when your data file can be parsed as an array of objects. ```ts title="src/content.config.ts" {5} -import { defineCollection, z } from 'astro:content'; +import { defineCollection } from 'astro:content'; import { file } from 'astro/loaders'; const dogs = defineCollection({ @@ -201,13 +201,15 @@ The `file()` loader will automatically detect and parse (based on their file ext The following example shows importing a CSV parser, then loading a `cats` collection into your project by passing both a file path and `parser` function to the `file()` loader: -```typescript title="src/content.config.ts" {3} "{ parser: (text) => parseCsv(text, { columns: true, skipEmptyLines: true })}" +```typescript title="src/content.config.ts" {3} "parser: (text) => parseCsv(text, { columns: true, skipEmptyLines: true })" import { defineCollection } from "astro:content"; import { file } from "astro/loaders"; import { parse as parseCsv } from "csv-parse/sync"; const cats = defineCollection({ - loader: file("src/data/cats.csv", { parser: (text) => parseCsv(text, { columns: true, skipEmptyLines: true })}) + loader: file("src/data/cats.csv", { + parser: (text) => parseCsv(text, { columns: true, skipEmptyLines: true }), + }), }); ``` @@ -222,6 +224,9 @@ The `parser` argument also allows you to load a single collection from a nested You can separate these collections by passing a custom `parser` to the `file()` loader for each collection: ```typescript title="src/content.config.ts" +import { file } from "astro/loaders"; +import { defineCollection } from "astro:content"; + const dogs = defineCollection({ loader: file("src/data/pets.json", { parser: (text) => JSON.parse(text).dogs }) }); @@ -247,6 +252,8 @@ You can define a loader inline, inside your collection, as an async function tha This is useful for loaders that don't need to manually control how the data is loaded and stored. Whenever the loader is called, it will clear the store and reload all the entries. ```ts title="src/content.config.ts" +import { defineCollection } from "astro:content"; + const countries = defineCollection({ loader: async () => { const response = await fetch("https://restcountries.com/v3.1/all"); @@ -740,8 +747,9 @@ Astro will generate some errors itself, depending on the response from the live - If a schema is defined for the collection and the data does not match the schema, Astro will return a `LiveCollectionValidationError`. - If the loader returns an invalid cache hint, Astro will return a `LiveCollectionCacheHintError`. The `cacheHint` field is optional, so if you do not have valid data to return, you can simply omit it. -```ts title="my-loader.ts" {9-11} +```ts title="my-loader.ts" {10-12} import type { LiveLoader } from 'astro/loaders'; +import type { MyData } from "./types"; import { MyLoaderError } from './errors.js'; export function myLoader(config): LiveLoader { @@ -861,6 +869,9 @@ export function productLoader(config: { You can create custom error types for [errors returned by your loader](#error-handling-in-live-loaders) and pass them as a generic to get proper typing: ```ts title="my-loader.ts" +import type { LiveLoader } from "astro/loaders"; +import type { MyData } from "./types" + class MyLoaderError extends Error { constructor( message: string, @@ -911,13 +922,18 @@ if (error) { Live loaders can provide cache hints to help with response caching. You can use this data to send HTTP cache headers or otherwise inform your caching strategy. ```ts title="my-loader.ts" +import type { LiveLoader } from "astro/loaders"; +import { byLastModified } from "./sort"; +import { loadStoreProduct, loadStoreProducts } from "./store"; +import type { MyData } from "./types"; + export function myLoader(config): LiveLoader { return { name: 'cached-loader', loadCollection: async ({ filter }) => { - // ... fetch data + const products = await loadStoreProducts(filter); return { - entries: data.map((item) => ({ + entries: products.map((item) => ({ id: item.id, data: item, // You can optionally provide cache hints for each entry @@ -930,14 +946,14 @@ export function myLoader(config): LiveLoader { // tags are merged from all entries // maxAge is the shortest maxAge of all entries and the collection // lastModified is the most recent lastModified of all entries and the collection - lastModified: new Date(item.lastModified), + lastModified: new Date(products.sort(byLastModified)[0].lastModified), tags: ['products'], maxAge: 300, // 5 minutes }, }; }, loadEntry: async ({ filter }) => { - // ... fetch single item + const item = await loadStoreProduct(filter); return { id: item.id, data: item, @@ -954,7 +970,7 @@ export function myLoader(config): LiveLoader { You can then use these hints in your pages: -```astro +```astro title="src/pages/store/[id].astro" --- export const prerender = false; // Not needed in 'server' mode @@ -1026,11 +1042,12 @@ export const collections = { products }; When using Zod schemas with live collections, validation errors are automatically caught and returned as `AstroError` objects: -```astro +```astro title="src/pages/store/index.astro" --- export const prerender = false; // Not needed in 'server' mode -import { getLiveEntry, LiveCollectionValidationError } from 'astro:content'; +import { LiveCollectionValidationError } from 'astro/content/runtime'; +import { getLiveEntry } from 'astro:content'; const { entry, error } = await getLiveEntry('products', '123'); @@ -1059,7 +1076,7 @@ These return entries with a unique `id`, and `data` object with all defined prop You can use these functions to access your live data, passing the name of the collection and optionally filtering conditions. -```astro +```astro title="src/pages/store/[slug].astro" --- export const prerender = false; // Not needed in 'server' mode @@ -1082,7 +1099,7 @@ If your live loader [returns a `rendered` property](#providing-rendered-content) You also have access to any [error returned by the live loader](#error-handling-in-live-loaders), for example, to rewrite to a 404 page when content cannot be displayed: -```astro "render(entry)" "" +```astro title="src/pages/store/[id].astro" "render(entry)" "" --- export const prerender = false; // Not needed in 'server' mode @@ -1113,11 +1130,12 @@ When you call `getLiveCollection()` or `getLiveEntry()`, the error will be one o These errors have a static `is()` method that you can use to check the type of error at runtime: -```astro "LiveEntryNotFoundError.is(error)" +```astro title="src/pages/store/[id].astro" "LiveEntryNotFoundError.is(error)" --- export const prerender = false; // Not needed in 'server' mode -import { getLiveEntry, LiveEntryNotFoundError } from 'astro:content'; +import { LiveEntryNotFoundError } from 'astro/content/runtime'; +import { getLiveEntry } from 'astro:content'; const { entry, error } = await getLiveEntry('products', Astro.params.id); @@ -1267,4 +1285,4 @@ In the following example, all YAML files in the `src/data/authors/` directory wi } ``` -See [“Associating schemas”](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml#associating-schemas) in the Red Hat YAML extension documentation for more details. \ No newline at end of file +See [“Associating schemas”](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml#associating-schemas) in the Red Hat YAML extension documentation for more details. diff --git a/src/content/docs/en/reference/content-loader-reference.mdx b/src/content/docs/en/reference/content-loader-reference.mdx index 1b35d7adbeac2..54f3f8e7bf959 100644 --- a/src/content/docs/en/reference/content-loader-reference.mdx +++ b/src/content/docs/en/reference/content-loader-reference.mdx @@ -11,14 +11,16 @@ Astro's Content Loader API allows you to load your data from any source, local ## What is a loader? -Astro loaders allow you to load data into [content collections](/en/guides/content-collections/), which can then be used in pages and components. The [built-in `glob()` and `file()` loaders](/en/guides/content-collections/#build-time-collection-loaders) are used to load content from the file system, and you can create your own loaders to load content from other sources. +Astro loaders allow you to load data into [content collections](/en/guides/content-collections/), which can then be used in pages and components. The [built-in `glob()` and `file()` loaders](#built-in-loaders) are used at built time to load content from the file system. You can also create your own [built-time loaders](/en/guides/content-collections/#custom-build-time-loaders) or [live loaders](/en/guides/content-collections/#creating-a-live-loader) to load content from other sources. -Each collection needs a loader defined in its schema. You can define a loader inline in your project's `src/content.config.ts` file, share one loader between multiple collections, or even [publish your loader to NPM as a package](/en/reference/publish-to-npm/) to share with others and be included in our integrations library. +Each collection needs to define a loader and an optional schema. For build-time collections, you can define a loader inline in your project's `src/content.config.ts` file or share an object loader between multiple collections. For live collections, you'll need to create your own live loader and import it in your `src/live.config.ts` file. In both cases, you can even [publish your loader to NPM as a package](/en/reference/publish-to-npm/) to share with others and be included in our integrations library. ## Built-in loaders Astro provides two built-in loaders to help you fetch your collections. Both offer options to suit a wide range of use cases. +Learn more about [using built-time loaders](/en/guides/content-collections/#build-time-content-collections) in the “Content Collections” guide. + ### `glob()` loader

@@ -31,19 +33,17 @@ The `glob()` loader creates entries from directories of files from anywhere on t This loader accepts an object with the following properties: `pattern`, `base` (optional), and `generateId` (optional). -```ts title="src/content.config.ts" {2,6,11,17-21} +```ts title="src/content.config.ts" {2,6,10,15-19} import { defineCollection } from 'astro:content'; import { glob } from 'astro/loaders'; const pages = defineCollection({ /* Retrieve all Markdown files in your pages directory. */ loader: glob({ pattern: "**/*.md", base: "./src/data/pages" }), - schema: /* ... */ }); const blog = defineCollection({ /* Retrieve all Markdown and MDX files in your blog directory. */ loader: glob({ pattern: "**/*.(md|mdx)", base: "./src/data/blog" }), - schema: /* ... */ }); const authors = defineCollection({ /* Retrieve all JSON files in your authors directory while retaining @@ -53,7 +53,6 @@ const authors = defineCollection({ base: "./src/data/authors", generateId: ({ entry }) => entry.replace(/\.json$/, ''), }), - schema: /* ... */ }); ``` @@ -104,21 +103,19 @@ The `file()` loader creates entries from a single file that contains an array of This loader accepts a `fileName` property and an optional object as second argument: -```ts title="src/content.config.ts" {2,6,11-13} +```ts title="src/content.config.ts" {2,6,10-12} import { defineCollection } from 'astro:content'; import { file } from 'astro/loaders'; const authors = defineCollection({ /* Retrieve all entries from a JSON file. */ loader: file("src/data/authors.json"), - schema: /* ... */ }); const products = defineCollection({ /* Retrieve all entries from a CSV file using a custom parser. */ loader: file("src/data/products.csv", { parser: (fileContent) => { /* your parser logic */ }, }), - schema: /* ... */ }); ``` @@ -160,6 +157,8 @@ An inline loader is an async function that returns an array or object containing The function can be async and must return either an array of entries that each contain a unique `id` field, or an object where each key is a unique ID and each value is the entry. Whenever the loader is invoked, it will clear the store and reload all the entries. ```ts title="src/content.config.ts" +import { defineCollection } from "astro:content"; + const countries = defineCollection({ loader: async () => { const response = await fetch("https://restcountries.com/v3.1/all"); @@ -171,7 +170,6 @@ const countries = defineCollection({ ...country, })); }, - schema: /* ... */ }); ``` @@ -182,7 +180,7 @@ A loader is an object with a [`load()` method](#load) that is called at build ti The recommended pattern is to define a function that accepts configuration options and returns the loader object, in the same way that you would normally define an Astro integration or Vite plugin. -```ts title=loader.ts +```ts title="src/loader.ts" import type { Loader, LoaderContext } from 'astro/loaders'; import { z } from 'astro:content'; import { loadFeedData } from "./feed.js"; @@ -211,16 +209,15 @@ export function myLoader(options: { url: string, apiKey: string }): Loader { These configuration options can then be set when defining a collection: ```ts title="src/content.config.ts" {2,5-8} -import { defineCollection, z } from 'astro:content'; -import myLoader from '../../loader.ts'; +import { defineCollection } from 'astro:content'; +import { myLoader } from './loader.ts'; -const blog = defineCollection({ +const blog = defineCollection({ loader: myLoader({ url: "https://api.example.com/posts", apiKey: "my-secret", - }), - schema: /* ... */ -}); + }), +}); ``` ### Live loaders @@ -290,7 +287,7 @@ export function articleLoader(config: { apiKey: string }): LiveLoader

{ } ``` -[See the `Content Collection` guide](/en/guides/content-collections/#creating-a-live-loader) for more information about creating a live loader and example usage. +[See the “Content Collections” guide](/en/guides/content-collections/#creating-a-live-loader) for more information about creating a live loader and example usage. ## Object loader API @@ -393,7 +390,7 @@ The full, resolved Astro configuration object with all defaults applied. See [th Validates and parses the data according to the collection schema. Pass data to this function to validate and parse it before storing it in the data store. -```ts title=loader.ts {14-17} +```ts title=loader.ts {15-18} import type { Loader } from "astro/loaders"; import { loadFeed } from "./feed.js"; @@ -407,8 +404,9 @@ export function feedLoader({ url }): Loader { store.clear(); for (const item of feed.items) { + const id = item.guid; const data = await parseData({ - id: item.guid, + id, data: item, }); store.set({ @@ -469,7 +467,7 @@ export function myLoader(settings): Loader { Generates a non-cryptographic content digest of an object or string. This can be used to track if the data has changed by setting [the `digest` field](#digest) of an entry. -```ts title=loader.ts {19,24} +```ts title=loader.ts {20,25} import type { Loader } from "astro/loaders"; import { loadFeed } from "./feed.js"; @@ -483,8 +481,9 @@ export function feedLoader({ url }): Loader { store.clear(); for (const item of feed.items) { + const id = item.guid; const data = await parseData({ - id: item.guid, + id, data: item, }); @@ -537,7 +536,10 @@ return { If the loader has been triggered by an integration, this may optionally contain extra data set by that integration. It is only set when the loader is triggered by an integration. See the [`astro:server:setup`](/en/reference/integrations-reference/#refreshcontent-option) hook reference for more information. -```ts title=loader.ts {5-8} +```ts title=loader.ts {8-11} +import type { Loader } from "astro/loaders"; +import { processWebhook } from "./lib/webhooks"; + export function myLoader(options: { url: string }): Loader { return { name: "my-loader", @@ -580,10 +582,11 @@ The returned object is a [`DataEntry`](#dataentry) object. Used after data has been [validated and parsed](#parsedata) to add an entry to the store, returning `true` if the entry was set. This returns `false` when the [`digest`](#digest) property determines that an entry has not changed and should not be updated. -```ts title=loader.ts {7-14} +```ts title=loader.ts {8-15} for (const item of feed.items) { + const id = item.guid; const data = await parseData({ - id: item.guid, + id, data: item, }); const digest = generateDigest(data); diff --git a/src/content/docs/en/reference/modules/astro-content.mdx b/src/content/docs/en/reference/modules/astro-content.mdx index 535305b245c3e..c3fbc18f29c7d 100644 --- a/src/content/docs/en/reference/modules/astro-content.mdx +++ b/src/content/docs/en/reference/modules/astro-content.mdx @@ -36,6 +36,7 @@ import { render } from 'astro:content'; ``` + ### `defineCollection()`

@@ -75,7 +76,7 @@ This function accepts the following properties: Either an object or a function that allows you to load data from any source, local or remote, into a build-time content collection. (For live collections, see the [live `loader`](#loader-1) property.) -[See the `Content Collection` guide](/en/guides/content-collections/#build-time-collection-loaders) for example usage. +[See the “Content Collections” guide](/en/guides/content-collections/#build-time-collection-loaders) for example usage. #### `schema` @@ -87,7 +88,7 @@ Either an object or a function that allows you to load data from any source, loc An optional Zod object or function that returns a Zod object to configure the type and shape of document frontmatter for a collection. Each value must use [a Zod validator](https://github.com/colinhacks/zod). (For live collections, see the [live `schema`](#schema-1) property.) -[See the `Content Collection` guide](/en/guides/content-collections/#defining-the-collection-schema) for example usage. +[See the “Content Collections” guide](/en/guides/content-collections/#defining-the-collection-schema) for example usage. ### `defineLiveCollection()` @@ -127,7 +128,7 @@ This function accepts the following properties: An object that allows you to load data at runtime from a remote source into a live content collection. (For build-time collections, see the [build-time `loader`](#loader) property.) -[See the `Content Collection` guide](/en/guides/content-collections/#creating-a-live-loader) for example usage. +[See the “Content Collections” guide](/en/guides/content-collections/#creating-a-live-loader) for example usage. #### `schema` @@ -141,7 +142,7 @@ An optional Zod object to configure the type and shape of your data for a live c When you define a schema, it will take precedence over the [live loader’s types](/en/reference/content-loader-reference/#live-loader-api) when you query the collection. -[See the `Content Collection` guide](/en/guides/content-collections/#using-zod-schemas-with-live-collections) for example usage. +[See the “Content Collections” guide](/en/guides/content-collections/#using-zod-schemas-with-live-collections) for example usage. ### `reference()` @@ -176,6 +177,7 @@ const authors = defineCollection({ export const collections = { blog, authors }; ``` + Validation of referenced entries happens at runtime when using `getEntry()` or `getEntries()`: ```astro title="src/pages/[posts].astro" @@ -183,7 +185,7 @@ Validation of referenced entries happens at runtime when using `getEntry()` or ` const relatedPosts = await getEntries(blogPost.data.relatedPosts); ``` -[See the `Content Collection` guide](/en/guides/content-collections/#defining-collection-references) for example usage. +[See the “Content Collections” guide](/en/guides/content-collections/#defining-collection-references) for example usage. ### `getCollection()` @@ -211,7 +213,7 @@ const draftBlogPosts = await getCollection('blog', ({ data }) => { --- ``` -[See the `Content Collection` guide](/en/guides/content-collections/#querying-build-time-collections) for example usage. +[See the “Content Collections” guide](/en/guides/content-collections/#querying-build-time-collections) for example usage. ### `getLiveCollection()` @@ -237,7 +239,7 @@ const featuredProducts = await getLiveCollection('products', { featured: true }) --- ``` -[See the `Content Collection` guide](/en/guides/content-collections/#accessing-live-data) for example usage. +[See the “Content Collections” guide](/en/guides/content-collections/#accessing-live-data) for example usage. ### `getEntry()` @@ -266,7 +268,7 @@ const enterpriseCaptainProfile = await getEntry(enterprisePost.data.captain); --- ``` -See the `Content Collections` guide for examples of [querying collection entries](/en/guides/content-collections/#querying-build-time-collections). +See the “Content Collections” guide for examples of [querying collection entries](/en/guides/content-collections/#querying-build-time-collections). ### `getLiveEntry()` @@ -290,7 +292,7 @@ const mattDraft = await getLiveEntry('blog', { --- ``` -See the `Content Collections` guide for examples of [querying collection entries](/en/guides/content-collections/#accessing-live-data). +See the “Content Collections” guide for examples of [querying collection entries](/en/guides/content-collections/#accessing-live-data). ### `getEntries()` @@ -327,7 +329,7 @@ A function to compile a given entry for rendering. This returns the following pr - `headings` - A generated list of headings, [mirroring Astro's `getHeadings()` utility](/en/guides/markdown-content/#available-properties) on Markdown and MDX imports. - `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 +```astro title="src/pages/blog/entry-1.astro" --- import { getEntry, render } from 'astro:content'; const entry = await getEntry('blog', 'entry-1'); @@ -340,7 +342,7 @@ const { Content, headings, remarkPluginFrontmatter } = await render(entry); --- ``` -[See the `Content Collection` guide](/en/guides/content-collections/#rendering-body-content) for example usage. +[See the “Content Collections” guide](/en/guides/content-collections/#rendering-body-content) for example usage. ## `astro:content` types @@ -447,8 +449,9 @@ This includes the following property: - `image` - The `image()` schema helper that allows you [to use local images in Content Collections](/en/guides/images/#images-in-content-collections) -```ts title="src/content.config.ts" +```ts title="src/content.config.ts" "SchemaContext" {4-8,12,15} import { defineCollection, z, type SchemaContext } from "astro:content"; +import { glob } from 'astro/loaders'; export const imageSchema = ({ image }: SchemaContext) => z.object({ @@ -457,7 +460,7 @@ export const imageSchema = ({ image }: SchemaContext) => }); const blog = defineCollection({ - loader: /* ... */, + loader: glob({ pattern: '**/*.md', base: './src/data/blog' }), schema: ({ image }) => z.object({ title: z.string(), permalink: z.string().optional(), From e2e90cc934319fe1d6b9b7c7d5e34e7acc53736a Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Mon, 10 Nov 2025 13:26:20 +0100 Subject: [PATCH 2/4] read more about Sarah's great suggestions Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com> --- src/content/docs/en/reference/content-loader-reference.mdx | 2 +- src/content/docs/en/reference/modules/astro-content.mdx | 2 +- 2 files changed, 2 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 54f3f8e7bf959..a3421a19b3c20 100644 --- a/src/content/docs/en/reference/content-loader-reference.mdx +++ b/src/content/docs/en/reference/content-loader-reference.mdx @@ -287,7 +287,7 @@ export function articleLoader(config: { apiKey: string }): LiveLoader

{ } ``` -[See the “Content Collections” guide](/en/guides/content-collections/#creating-a-live-loader) for more information about creating a live loader and example usage. +See [how to create a live loader](/en/guides/content-collections/#creating-a-live-loader) with example usage. ## Object loader API diff --git a/src/content/docs/en/reference/modules/astro-content.mdx b/src/content/docs/en/reference/modules/astro-content.mdx index c3fbc18f29c7d..09100e90e3506 100644 --- a/src/content/docs/en/reference/modules/astro-content.mdx +++ b/src/content/docs/en/reference/modules/astro-content.mdx @@ -76,7 +76,7 @@ This function accepts the following properties: Either an object or a function that allows you to load data from any source, local or remote, into a build-time content collection. (For live collections, see the [live `loader`](#loader-1) property.) -[See the “Content Collections” guide](/en/guides/content-collections/#build-time-collection-loaders) for example usage. +Learn about [build-time collection loaders](/en/guides/content-collections/#build-time-collection-loaders) with guided explanations and example usage. #### `schema` From 0f14b21647eeda1044e479ba24b072178c60f4b6 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Mon, 10 Nov 2025 13:57:10 +0100 Subject: [PATCH 3/4] update read more wording in references --- .../en/reference/content-loader-reference.mdx | 2 +- .../en/reference/modules/astro-content.mdx | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/content/docs/en/reference/content-loader-reference.mdx b/src/content/docs/en/reference/content-loader-reference.mdx index a3421a19b3c20..782be0865af44 100644 --- a/src/content/docs/en/reference/content-loader-reference.mdx +++ b/src/content/docs/en/reference/content-loader-reference.mdx @@ -19,7 +19,7 @@ Each collection needs to define a loader and an optional schema. For build-time Astro provides two built-in loaders to help you fetch your collections. Both offer options to suit a wide range of use cases. -Learn more about [using built-time loaders](/en/guides/content-collections/#build-time-content-collections) in the “Content Collections” guide. +Learn more about [using built-time loaders](/en/guides/content-collections/#build-time-content-collections) with guided explanations and example usage. ### `glob()` loader diff --git a/src/content/docs/en/reference/modules/astro-content.mdx b/src/content/docs/en/reference/modules/astro-content.mdx index 09100e90e3506..603e2d64c3475 100644 --- a/src/content/docs/en/reference/modules/astro-content.mdx +++ b/src/content/docs/en/reference/modules/astro-content.mdx @@ -76,7 +76,7 @@ This function accepts the following properties: Either an object or a function that allows you to load data from any source, local or remote, into a build-time content collection. (For live collections, see the [live `loader`](#loader-1) property.) -Learn about [build-time collection loaders](/en/guides/content-collections/#build-time-collection-loaders) with guided explanations and example usage. +Learn about [build-time collection loaders](/en/guides/content-collections/#build-time-collection-loaders) with guided explanations and example usage. #### `schema` @@ -88,7 +88,7 @@ Learn about [build-time collection loaders](/en/guides/content-collections/#buil An optional Zod object or function that returns a Zod object to configure the type and shape of document frontmatter for a collection. Each value must use [a Zod validator](https://github.com/colinhacks/zod). (For live collections, see the [live `schema`](#schema-1) property.) -[See the “Content Collections” guide](/en/guides/content-collections/#defining-the-collection-schema) for example usage. +Learn about [defining a collection schema](/en/guides/content-collections/#defining-the-collection-schema) using Zod with guided explanations, example usage, and common datatypes. ### `defineLiveCollection()` @@ -128,7 +128,7 @@ This function accepts the following properties: An object that allows you to load data at runtime from a remote source into a live content collection. (For build-time collections, see the [build-time `loader`](#loader) property.) -[See the “Content Collections” guide](/en/guides/content-collections/#creating-a-live-loader) for example usage. +Learn how to [create a live loader](/en/guides/content-collections/#creating-a-live-loader) with guided explanations and example usage. #### `schema` @@ -142,7 +142,7 @@ An optional Zod object to configure the type and shape of your data for a live c When you define a schema, it will take precedence over the [live loader’s types](/en/reference/content-loader-reference/#live-loader-api) when you query the collection. -[See the “Content Collections” guide](/en/guides/content-collections/#using-zod-schemas-with-live-collections) for example usage. +Learn about [using Zod schemas with live collections](/en/guides/content-collections/#using-zod-schemas-with-live-collections) through guided explanations and usage examples. ### `reference()` @@ -185,7 +185,7 @@ Validation of referenced entries happens at runtime when using `getEntry()` or ` const relatedPosts = await getEntries(blogPost.data.relatedPosts); ``` -[See the “Content Collections” guide](/en/guides/content-collections/#defining-collection-references) for example usage. +Learn how to [define and use collections references](/en/guides/content-collections/#defining-collection-references) with guided explanations and usage examples. ### `getCollection()` @@ -213,7 +213,7 @@ const draftBlogPosts = await getCollection('blog', ({ data }) => { --- ``` -[See the “Content Collections” guide](/en/guides/content-collections/#querying-build-time-collections) for example usage. +Learn how to [query build time collections](/en/guides/content-collections/#querying-build-time-collections) with guided explanations and example usage. ### `getLiveCollection()` @@ -239,7 +239,7 @@ const featuredProducts = await getLiveCollection('products', { featured: true }) --- ``` -[See the “Content Collections” guide](/en/guides/content-collections/#accessing-live-data) for example usage. +Learn how to [access live collections data](/en/guides/content-collections/#accessing-live-data) with guided explanations and example usage. ### `getEntry()` @@ -268,7 +268,7 @@ const enterpriseCaptainProfile = await getEntry(enterprisePost.data.captain); --- ``` -See the “Content Collections” guide for examples of [querying collection entries](/en/guides/content-collections/#querying-build-time-collections). +Learn more about [querying build time collections](/en/guides/content-collections/#querying-build-time-collections) with guided explanations and example usage. ### `getLiveEntry()` @@ -292,7 +292,7 @@ const mattDraft = await getLiveEntry('blog', { --- ``` -See the “Content Collections” guide for examples of [querying collection entries](/en/guides/content-collections/#accessing-live-data). +Learn how to [access live collections data](/en/guides/content-collections/#accessing-live-data) with guided explanations and example usage. ### `getEntries()` @@ -342,7 +342,7 @@ const { Content, headings, remarkPluginFrontmatter } = await render(entry); --- ``` -[See the “Content Collections” guide](/en/guides/content-collections/#rendering-body-content) for example usage. +Learn how to [render the body content](/en/guides/content-collections/#rendering-body-content) with guided explanations and example usage. ## `astro:content` types From d30a69b2c35a8aa7e042db5831360fb3eafb44e3 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Mon, 10 Nov 2025 14:36:54 +0100 Subject: [PATCH 4/4] Sarah's wording fixes Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com> --- 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 603e2d64c3475..dc7270ba048da 100644 --- a/src/content/docs/en/reference/modules/astro-content.mdx +++ b/src/content/docs/en/reference/modules/astro-content.mdx @@ -185,7 +185,7 @@ Validation of referenced entries happens at runtime when using `getEntry()` or ` const relatedPosts = await getEntries(blogPost.data.relatedPosts); ``` -Learn how to [define and use collections references](/en/guides/content-collections/#defining-collection-references) with guided explanations and usage examples. +Learn how to [define and use collection references](/en/guides/content-collections/#defining-collection-references) with guided explanations and usage examples. ### `getCollection()` @@ -342,7 +342,7 @@ const { Content, headings, remarkPluginFrontmatter } = await render(entry); --- ``` -Learn how to [render the body content](/en/guides/content-collections/#rendering-body-content) with guided explanations and example usage. +Learn how to [render the body content of entries](/en/guides/content-collections/#rendering-body-content) with guided explanations and example usage. ## `astro:content` types