Skip to content

Commit

Permalink
docs: content collection config changes
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo committed Nov 26, 2024
1 parent 8aa6621 commit 57c925e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 31 deletions.
19 changes: 10 additions & 9 deletions docs/src/content/docs/guides/i18n.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,16 @@ You can provide translations for additional languages you support — or overrid

<Steps>

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() }),
};
```

Expand Down Expand Up @@ -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(),
Expand Down
5 changes: 2 additions & 3 deletions docs/src/content/docs/guides/project-structure.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions docs/src/content/docs/guides/site-search.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,19 @@ Add translations of the modal UI for your language using Starlight’s built-in

<Steps>

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() }),
}),
};
Expand Down
11 changes: 6 additions & 5 deletions docs/src/content/docs/manual-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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() }),
};
```

Expand Down
23 changes: 14 additions & 9 deletions docs/src/content/docs/reference/frontmatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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.
Expand All @@ -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({
Expand Down

0 comments on commit 57c925e

Please sign in to comment.