From 57c925e9b9831f3f40e32bce0bb03270c5b6159c Mon Sep 17 00:00:00 2001 From: HiDeoo <494699+HiDeoo@users.noreply.github.com> Date: Tue, 26 Nov 2024 16:40:42 +0100 Subject: [PATCH] docs: content collection config changes --- docs/src/content/docs/guides/i18n.mdx | 19 +++++++-------- .../content/docs/guides/project-structure.mdx | 5 ++-- docs/src/content/docs/guides/site-search.mdx | 11 +++++---- docs/src/content/docs/manual-setup.mdx | 11 +++++---- .../src/content/docs/reference/frontmatter.md | 23 +++++++++++-------- 5 files changed, 38 insertions(+), 31 deletions(-) diff --git a/docs/src/content/docs/guides/i18n.mdx b/docs/src/content/docs/guides/i18n.mdx index 9844fefddf2..22b44b42802 100644 --- a/docs/src/content/docs/guides/i18n.mdx +++ b/docs/src/content/docs/guides/i18n.mdx @@ -188,16 +188,16 @@ You can provide translations for additional languages you support — or overrid -1. Configure the `i18n` data collection in `src/content/config.ts` if it isn’t configured already: +1. Configure the `i18n` data collection in `src/content.config.ts` if it isn’t configured already: - ```diff lang="js" ins=/, (i18nSchema)/ - // src/content/config.ts - import { defineCollection } from 'astro:content'; + ```diff lang="js" ins=/, (i18nLoader|i18nSchema)/ + // src/content.config.ts + import { docsLoader, i18nLoader } from '@astrojs/starlight/loader'; import { docsSchema, i18nSchema } from '@astrojs/starlight/schema'; export const collections = { - docs: defineCollection({ schema: docsSchema() }), - + i18n: defineCollection({ type: 'data', schema: i18nSchema() }), + docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }), + + i18n: defineCollection({ loader: i18nLoader(), schema: i18nSchema() }), }; ``` @@ -257,14 +257,15 @@ Add custom keys to your site’s translation dictionaries by setting `extend` in In the following example, a new, optional `custom.label` key is added to the default keys: ```diff lang="js" -// src/content/config.ts +// src/content.config.ts import { defineCollection, z } from 'astro:content'; +import { docsLoader, i18nLoader } from '@astrojs/starlight/loader'; import { docsSchema, i18nSchema } from '@astrojs/starlight/schema'; export const collections = { - docs: defineCollection({ schema: docsSchema() }), + docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }), i18n: defineCollection({ - type: 'data', + loader: i18nLoader(), schema: i18nSchema({ + extend: z.object({ + 'custom.label': z.string().optional(), diff --git a/docs/src/content/docs/guides/project-structure.mdx b/docs/src/content/docs/guides/project-structure.mdx index f32bc16b754..eca222a4ce8 100644 --- a/docs/src/content/docs/guides/project-structure.mdx +++ b/docs/src/content/docs/guides/project-structure.mdx @@ -10,7 +10,7 @@ Starlight projects generally follow the same file and directory structure as oth ## Files and directories - `astro.config.mjs` — The Astro configuration file; includes the Starlight integration and configuration. -- `src/content/config.ts` — Content collections configuration file; adds Starlight’s frontmatter schemas to your project. +- `src/content.config.ts` — Content collections configuration file; adds Starlight’s frontmatter schemas to your project. - `src/content/docs/` — Content files. Starlight turns each `.md`, `.mdx` or `.mdoc` file in this directory into a page on your site. - `src/content/i18n/` (optional) — Translation data to support [internationalization](/guides/i18n/). - `src/` — Other source code and files (components, styles, images, etc.) for your project. @@ -39,8 +39,7 @@ import { FileTree } from '@astrojs/starlight/components'; - 01-getting-started.md - 02-advanced.md - index.mdx - - config.ts - - env.d.ts + - content.config.ts - astro.config.mjs - package.json - tsconfig.json diff --git a/docs/src/content/docs/guides/site-search.mdx b/docs/src/content/docs/guides/site-search.mdx index 083c245ee9c..4adf391790a 100644 --- a/docs/src/content/docs/guides/site-search.mdx +++ b/docs/src/content/docs/guides/site-search.mdx @@ -124,18 +124,19 @@ Add translations of the modal UI for your language using Starlight’s built-in -1. Extend Starlight’s `i18n` content collection definition with the DocSearch schema in `src/content/config.ts`: +1. Extend Starlight’s `i18n` content collection definition with the DocSearch schema in `src/content.config.ts`: - ```js ins={4} ins=/{ extend: .+ }/ - // src/content/config.ts + ```js ins={5} ins=/{ extend: .+ }/ + // src/content.config.ts import { defineCollection } from 'astro:content'; + import { docsLoader, i18nLoader } from '@astrojs/starlight/loader'; import { docsSchema, i18nSchema } from '@astrojs/starlight/schema'; import { docSearchI18nSchema } from '@astrojs/starlight-docsearch/schema'; export const collections = { - docs: defineCollection({ schema: docsSchema() }), + docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }), i18n: defineCollection({ - type: 'data', + loader: i18nLoader(), schema: i18nSchema({ extend: docSearchI18nSchema() }), }), }; diff --git a/docs/src/content/docs/manual-setup.mdx b/docs/src/content/docs/manual-setup.mdx index 07465d9f167..e98df97d326 100644 --- a/docs/src/content/docs/manual-setup.mdx +++ b/docs/src/content/docs/manual-setup.mdx @@ -62,17 +62,18 @@ Find all available options in the [Starlight configuration reference](/reference ### Configure content collections -Starlight is built on top of Astro’s [content collections](https://docs.astro.build/en/guides/content-collections/), which are configured in the `src/content/config.ts` file. +Starlight is built on top of Astro’s [content collections](https://docs.astro.build/en/guides/content-collections/), which are configured in the `src/content.config.ts` file. -Create or update the content config file, adding a `docs` collection that uses Starlight’s `docsSchema`: +Create or update the content config file, adding a `docs` collection that uses Starlight’s `docsLoader` and `docsSchema`: -```js ins={3,6} -// src/content/config.ts +```js ins={3,7} +// src/content.config.ts import { defineCollection } from 'astro:content'; +import { docsLoader } from '@astrojs/starlight/loader'; import { docsSchema } from '@astrojs/starlight/schema'; export const collections = { - docs: defineCollection({ schema: docsSchema() }), + docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }), }; ``` diff --git a/docs/src/content/docs/reference/frontmatter.md b/docs/src/content/docs/reference/frontmatter.md index 75b564442b5..2779ed86c10 100644 --- a/docs/src/content/docs/reference/frontmatter.md +++ b/docs/src/content/docs/reference/frontmatter.md @@ -397,19 +397,20 @@ sidebar: ## Customize frontmatter schema -The frontmatter schema for Starlight’s `docs` content collection is configured in `src/content/config.ts` using the `docsSchema()` helper: +The frontmatter schema for Starlight’s `docs` content collection is configured in `src/content.config.ts` using the `docsSchema()` helper: -```ts {3,6} -// src/content/config.ts +```ts {4,7} +// src/content.config.ts import { defineCollection } from 'astro:content'; +import { docsLoader, i18nLoader } from '@astrojs/starlight/loader'; import { docsSchema } from '@astrojs/starlight/schema'; export const collections = { - docs: defineCollection({ schema: docsSchema() }), + docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }), }; ``` -Learn more about content collection schemas in [“Defining a collection schema”](https://docs.astro.build/en/guides/content-collections/#defining-a-collection-schema) in the Astro docs. +Learn more about content collection schemas in [“Defining a collection schema”](https://docs.astro.build/en/guides/content-collections/#defining-the-collection-schema) in the Astro docs. `docsSchema()` takes the following options: @@ -423,13 +424,15 @@ The value should be a [Zod schema](https://docs.astro.build/en/guides/content-co In the following example, we provide a stricter type for `description` to make it required and add a new optional `category` field: -```ts {8-13} -// src/content/config.ts +```ts {10-15} +// src/content.config.ts import { defineCollection, z } from 'astro:content'; +import { docsLoader } from '@astrojs/starlight/loader'; import { docsSchema } from '@astrojs/starlight/schema'; export const collections = { docs: defineCollection({ + loader: docsLoader(), schema: docsSchema({ extend: z.object({ // Make a built-in field required instead of optional. @@ -444,13 +447,15 @@ export const collections = { To take advantage of the [Astro `image()` helper](https://docs.astro.build/en/guides/images/#images-in-content-collections), use a function that returns your schema extension: -```ts {8-13} -// src/content/config.ts +```ts {10-15} +// src/content.config.ts import { defineCollection, z } from 'astro:content'; +import { docsLoader } from '@astrojs/starlight/loader'; import { docsSchema } from '@astrojs/starlight/schema'; export const collections = { docs: defineCollection({ + loader: docsLoader(), schema: docsSchema({ extend: ({ image }) => { return z.object({