Skip to content

Commit

Permalink
docs: update defineContentConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Dec 9, 2024
1 parent cf85cd4 commit ed704c4
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 112 deletions.
50 changes: 27 additions & 23 deletions docs/content/docs/2.collections/1.collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ Create a `content.config.ts` file in your project's root directory. This special
Here's a basic example:

```ts [content.config.ts]
import { defineCollection } from '@nuxt/content'

export const collections = {
docs: defineCollection({
// Load every file inside the `content` directory
source: '**',
// Specify the type of content in this collection
type: 'page'
})
}
import { defineCollection, defineContentConfig } from '@nuxt/content'

export default defineContentConfig({
collections: {
docs: defineCollection({
// Load every file inside the `content` directory
source: '**',
// Specify the type of content in this collection
type: 'page'
})
}
})
```

### Collection Schema
Expand All @@ -51,20 +53,22 @@ Schemas enforce data consistency within a collection and serve as the source of
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:

```ts [content.config.ts]
import { defineCollection, z } from '@nuxt/content'

export const collections = {
blog: defineCollection({
source: 'blog/*.md',
type: 'page',
// Define custom schema for docs collection
schema: z.object({
tags: z.array(z.string()),
image: z.string(),
date: z.date()
import { defineCollection, defineContentConfig, z } from '@nuxt/content'

export default defineContentConfig({
collections: {
blog: defineCollection({
source: 'blog/*.md',
type: 'page',
// Define custom schema for docs collection
schema: z.object({
tags: z.array(z.string()),
image: z.string(),
date: z.date()
})
})
})
}
}
})
```

::note
Expand Down
18 changes: 10 additions & 8 deletions docs/content/docs/2.collections/3.sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ description: Learn how to import your files in Nuxt Content collections.
Nuxt Content provides several ways to import content files into your collection. You can configure the source by using the `source` property within `defineCollection`:

```ts [content.config.ts]
import { defineCollection } from '@nuxt/content'

export const collections = {
docs: defineCollection({
source: '**',
type: 'page'
})
}
import { defineCollection, defineContentConfig } from '@nuxt/content'

export default defineContentConfig({
collections: {
docs: defineCollection({
source: '**',
type: 'page'
})
}
})
```

## `source`
Expand Down
20 changes: 12 additions & 8 deletions docs/content/docs/3.files/1.markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ description: Create and query Markdown files in your Nuxt applications and use
### Define a Collection

```ts [content.config.ts]
export const collections = {
blog: defineCollection({
type: 'page',
source: 'blog/*.md',
schema: z.object({
date: z.string()
import { defineCollection, defineContentConfig, z } from '@nuxt/content'

export default defineContentConfig({
collections: {
blog: defineCollection({
type: 'page',
source: 'blog/*.md',
schema: z.object({
date: z.string()
})
})
})
}
}
})
```

::note{to="/docs/collections/types#page-type"}
Expand Down
24 changes: 14 additions & 10 deletions docs/content/docs/3.files/2.yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ description: How to define, write and query YAML data.
## Define Collection

```ts [content.config.ts]
export const collections = {
authors: defineCollection({
type: 'data',
source: 'authors/**.yml',
schema: z.object({
name: z.string(),
avatar: z.string(),
url: z.string()
import { defineCollection, defineContentConfig, z } from '@nuxt/content'

export default defineContentConfig({
collections: {
authors: defineCollection({
type: 'data',
source: 'authors/**.yml',
schema: z.object({
name: z.string(),
avatar: z.string(),
url: z.string()
})
})
})
}
}
})

```

Expand Down
24 changes: 14 additions & 10 deletions docs/content/docs/3.files/3.json.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ description: How to define, write and query JSON data.
## Define Collection

```ts [content.config.ts]
export const collections = {
authors: defineCollection({
type: 'data',
source: 'authors/**.json',
schema: z.object({
name: z.string(),
avatar: z.string(),
url: z.string()
import { defineCollection, defineContentConfig, z } from '@nuxt/content'

export default defineContentConfig({
collections: {
authors: defineCollection({
type: 'data',
source: 'authors/**.json',
schema: z.object({
name: z.string(),
avatar: z.string(),
url: z.string()
})
})
})
}
}
})

```

Expand Down
23 changes: 13 additions & 10 deletions docs/content/docs/6.advanced/2.raw-content.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ In order to ship raw contents to production you need to define `rawbody` field i
Nuxt Content will detect this magical field in your schema and fill it with the raw content.

```ts [content.config.ts]
import { defineCollection, z } from '@nuxt/content'

export const collections = {
docs: defineCollection({
source: '**',
type: 'page',
schema: z.object({
rawbody: z.string()

import { defineCollection, defineContentConfig, z } from '@nuxt/content'

export default defineContentConfig({
collections: {
docs: defineCollection({
source: '**',
type: 'page',
schema: z.object({
rawbody: z.string()
})
})
})
}
}
})
```

And you can use `queryCollection()` to fetch the raw content.
Expand Down
20 changes: 11 additions & 9 deletions examples/blog/content.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { defineCollection, z } from '@nuxt/content'
import { defineCollection, defineContentConfig, z } from '@nuxt/content'

export const collections = {
blog: defineCollection({
type: 'page',
source: 'blog/**',
schema: z.object({
date: z.string(),
export default defineContentConfig({
collections: {
blog: defineCollection({
type: 'page',
source: 'blog/**',
schema: z.object({
date: z.string(),
}),
}),
}),
}
},
})
56 changes: 29 additions & 27 deletions examples/i18n/content.config.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
import { defineCollection, z } from '@nuxt/content'
import { defineCollection, defineContentConfig, z } from '@nuxt/content'

const commonSchema = z.object({})

export const collections = {
content_en: defineCollection({
type: 'page',
source: {
include: 'en/**',
prefix: '',
},
schema: commonSchema,
}),
content_fr: defineCollection({
type: 'page',
source: {
include: 'fr/**',
prefix: '',
},
schema: commonSchema,
}),
content_fa: defineCollection({
type: 'page',
source: {
include: 'fa/**',
prefix: '',
},
schema: commonSchema,
}),
}
export default defineContentConfig({
collections: {
content_en: defineCollection({
type: 'page',
source: {
include: 'en/**',
prefix: '',
},
schema: commonSchema,
}),
content_fr: defineCollection({
type: 'page',
source: {
include: 'fr/**',
prefix: '',
},
schema: commonSchema,
}),
content_fa: defineCollection({
type: 'page',
source: {
include: 'fa/**',
prefix: '',
},
schema: commonSchema,
}),
},
})
16 changes: 9 additions & 7 deletions examples/ui-pro/content.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { defineCollection } from '@nuxt/content'
import { defineCollection, defineContentConfig } from '@nuxt/content'

export const collections = {
content: defineCollection({
type: 'page',
source: '**',
}),
}
export default defineContentConfig({
collections: {
content: defineCollection({
type: 'page',
source: '**',
}),
},
})

0 comments on commit ed704c4

Please sign in to comment.