Skip to content

Commit ed704c4

Browse files
committed
docs: update defineContentConfig
1 parent cf85cd4 commit ed704c4

File tree

9 files changed

+139
-112
lines changed

9 files changed

+139
-112
lines changed

docs/content/docs/2.collections/1.collections.md

+27-23
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,18 @@ Create a `content.config.ts` file in your project's root directory. This special
3232
Here's a basic example:
3333

3434
```ts [content.config.ts]
35-
import { defineCollection } from '@nuxt/content'
36-
37-
export const collections = {
38-
docs: defineCollection({
39-
// Load every file inside the `content` directory
40-
source: '**',
41-
// Specify the type of content in this collection
42-
type: 'page'
43-
})
44-
}
35+
import { defineCollection, defineContentConfig } from '@nuxt/content'
36+
37+
export default defineContentConfig({
38+
collections: {
39+
docs: defineCollection({
40+
// Load every file inside the `content` directory
41+
source: '**',
42+
// Specify the type of content in this collection
43+
type: 'page'
44+
})
45+
}
46+
})
4547
```
4648

4749
### Collection Schema
@@ -51,20 +53,22 @@ Schemas enforce data consistency within a collection and serve as the source of
5153
On top of the [built-in fields](#built-in-fields), you can define a schema by adding the `schema` property to your collection by using a [`zod`](https://zod.dev) schema:
5254

5355
```ts [content.config.ts]
54-
import { defineCollection, z } from '@nuxt/content'
55-
56-
export const collections = {
57-
blog: defineCollection({
58-
source: 'blog/*.md',
59-
type: 'page',
60-
// Define custom schema for docs collection
61-
schema: z.object({
62-
tags: z.array(z.string()),
63-
image: z.string(),
64-
date: z.date()
56+
import { defineCollection, defineContentConfig, z } from '@nuxt/content'
57+
58+
export default defineContentConfig({
59+
collections: {
60+
blog: defineCollection({
61+
source: 'blog/*.md',
62+
type: 'page',
63+
// Define custom schema for docs collection
64+
schema: z.object({
65+
tags: z.array(z.string()),
66+
image: z.string(),
67+
date: z.date()
68+
})
6569
})
66-
})
67-
}
70+
}
71+
})
6872
```
6973

7074
::note

docs/content/docs/2.collections/3.sources.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ description: Learn how to import your files in Nuxt Content collections.
88
Nuxt Content provides several ways to import content files into your collection. You can configure the source by using the `source` property within `defineCollection`:
99

1010
```ts [content.config.ts]
11-
import { defineCollection } from '@nuxt/content'
12-
13-
export const collections = {
14-
docs: defineCollection({
15-
source: '**',
16-
type: 'page'
17-
})
18-
}
11+
import { defineCollection, defineContentConfig } from '@nuxt/content'
12+
13+
export default defineContentConfig({
14+
collections: {
15+
docs: defineCollection({
16+
source: '**',
17+
type: 'page'
18+
})
19+
}
20+
})
1921
```
2022

2123
## `source`

docs/content/docs/3.files/1.markdown.md

+12-8
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ description: Create and query Markdown files in your Nuxt applications and use
99
### Define a Collection
1010

1111
```ts [content.config.ts]
12-
export const collections = {
13-
blog: defineCollection({
14-
type: 'page',
15-
source: 'blog/*.md',
16-
schema: z.object({
17-
date: z.string()
12+
import { defineCollection, defineContentConfig, z } from '@nuxt/content'
13+
14+
export default defineContentConfig({
15+
collections: {
16+
blog: defineCollection({
17+
type: 'page',
18+
source: 'blog/*.md',
19+
schema: z.object({
20+
date: z.string()
21+
})
1822
})
19-
})
20-
}
23+
}
24+
})
2125
```
2226

2327
::note{to="/docs/collections/types#page-type"}

docs/content/docs/3.files/2.yaml.md

+14-10
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@ description: How to define, write and query YAML data.
66
## Define Collection
77

88
```ts [content.config.ts]
9-
export const collections = {
10-
authors: defineCollection({
11-
type: 'data',
12-
source: 'authors/**.yml',
13-
schema: z.object({
14-
name: z.string(),
15-
avatar: z.string(),
16-
url: z.string()
9+
import { defineCollection, defineContentConfig, z } from '@nuxt/content'
10+
11+
export default defineContentConfig({
12+
collections: {
13+
authors: defineCollection({
14+
type: 'data',
15+
source: 'authors/**.yml',
16+
schema: z.object({
17+
name: z.string(),
18+
avatar: z.string(),
19+
url: z.string()
20+
})
1721
})
18-
})
19-
}
22+
}
23+
})
2024

2125
```
2226

docs/content/docs/3.files/3.json.md

+14-10
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@ description: How to define, write and query JSON data.
66
## Define Collection
77

88
```ts [content.config.ts]
9-
export const collections = {
10-
authors: defineCollection({
11-
type: 'data',
12-
source: 'authors/**.json',
13-
schema: z.object({
14-
name: z.string(),
15-
avatar: z.string(),
16-
url: z.string()
9+
import { defineCollection, defineContentConfig, z } from '@nuxt/content'
10+
11+
export default defineContentConfig({
12+
collections: {
13+
authors: defineCollection({
14+
type: 'data',
15+
source: 'authors/**.json',
16+
schema: z.object({
17+
name: z.string(),
18+
avatar: z.string(),
19+
url: z.string()
20+
})
1721
})
18-
})
19-
}
22+
}
23+
})
2024

2125
```
2226

docs/content/docs/6.advanced/2.raw-content.md

+13-10
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@ In order to ship raw contents to production you need to define `rawbody` field i
1010
Nuxt Content will detect this magical field in your schema and fill it with the raw content.
1111

1212
```ts [content.config.ts]
13-
import { defineCollection, z } from '@nuxt/content'
14-
15-
export const collections = {
16-
docs: defineCollection({
17-
source: '**',
18-
type: 'page',
19-
schema: z.object({
20-
rawbody: z.string()
13+
14+
import { defineCollection, defineContentConfig, z } from '@nuxt/content'
15+
16+
export default defineContentConfig({
17+
collections: {
18+
docs: defineCollection({
19+
source: '**',
20+
type: 'page',
21+
schema: z.object({
22+
rawbody: z.string()
23+
})
2124
})
22-
})
23-
}
25+
}
26+
})
2427
```
2528

2629
And you can use `queryCollection()` to fetch the raw content.

examples/blog/content.config.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { defineCollection, z } from '@nuxt/content'
1+
import { defineCollection, defineContentConfig, z } from '@nuxt/content'
22

3-
export const collections = {
4-
blog: defineCollection({
5-
type: 'page',
6-
source: 'blog/**',
7-
schema: z.object({
8-
date: z.string(),
3+
export default defineContentConfig({
4+
collections: {
5+
blog: defineCollection({
6+
type: 'page',
7+
source: 'blog/**',
8+
schema: z.object({
9+
date: z.string(),
10+
}),
911
}),
10-
}),
11-
}
12+
},
13+
})

examples/i18n/content.config.ts

+29-27
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
1-
import { defineCollection, z } from '@nuxt/content'
1+
import { defineCollection, defineContentConfig, z } from '@nuxt/content'
22

33
const commonSchema = z.object({})
44

5-
export const collections = {
6-
content_en: defineCollection({
7-
type: 'page',
8-
source: {
9-
include: 'en/**',
10-
prefix: '',
11-
},
12-
schema: commonSchema,
13-
}),
14-
content_fr: defineCollection({
15-
type: 'page',
16-
source: {
17-
include: 'fr/**',
18-
prefix: '',
19-
},
20-
schema: commonSchema,
21-
}),
22-
content_fa: defineCollection({
23-
type: 'page',
24-
source: {
25-
include: 'fa/**',
26-
prefix: '',
27-
},
28-
schema: commonSchema,
29-
}),
30-
}
5+
export default defineContentConfig({
6+
collections: {
7+
content_en: defineCollection({
8+
type: 'page',
9+
source: {
10+
include: 'en/**',
11+
prefix: '',
12+
},
13+
schema: commonSchema,
14+
}),
15+
content_fr: defineCollection({
16+
type: 'page',
17+
source: {
18+
include: 'fr/**',
19+
prefix: '',
20+
},
21+
schema: commonSchema,
22+
}),
23+
content_fa: defineCollection({
24+
type: 'page',
25+
source: {
26+
include: 'fa/**',
27+
prefix: '',
28+
},
29+
schema: commonSchema,
30+
}),
31+
},
32+
})

examples/ui-pro/content.config.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { defineCollection } from '@nuxt/content'
1+
import { defineCollection, defineContentConfig } from '@nuxt/content'
22

3-
export const collections = {
4-
content: defineCollection({
5-
type: 'page',
6-
source: '**',
7-
}),
8-
}
3+
export default defineContentConfig({
4+
collections: {
5+
content: defineCollection({
6+
type: 'page',
7+
source: '**',
8+
}),
9+
},
10+
})

0 commit comments

Comments
 (0)