Skip to content

Commit 7704f98

Browse files
committed
docs: update
1 parent 5c5759a commit 7704f98

File tree

14 files changed

+183
-130
lines changed

14 files changed

+183
-130
lines changed

docs/app/pages/docs/[...slug].vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const { data } = await useAsyncData(route.path, () => Promise.all([
1616
]), {
1717
transform: ([page, surround]) => ({ page, surround }),
1818
})
19-
if (!data.value) {
19+
if (!data.value || !data.value.page) {
2020
throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true })
2121
}
2222
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
title: Collections
3+
icon: i-lucide-database

docs/content/docs/2.usage/1.collections.md renamed to docs/content/docs/2.collections/1.collections.md

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Define Collections
2+
title: Define
33
description: 'Learn how to define and configure content collections in your Nuxt application.'
44
---
55

@@ -43,11 +43,6 @@ export const collections = {
4343
}
4444
```
4545

46-
47-
::note{to="/docs/usage/types"}
48-
Learn more about collection types.
49-
::
50-
5146
### Collection Schema
5247

5348
Schemas enforce data consistency within a collection and serve as the source of truth for TypeScript types.
@@ -119,7 +114,13 @@ type Collection = {
119114
// Zod schema for content validation and typing
120115
schema?: ZodObject<T>
121116
}
117+
```
122118
119+
::note{to="/docs/usage/types"}
120+
Learn more about collection types.
121+
::
122+
123+
```ts
123124
type CollectionSource = {
124125
// Glob pattern for content matching
125126
include: string
@@ -134,24 +135,8 @@ type CollectionSource = {
134135
}
135136
```
136137
137-
### Built-in Fields
138-
139-
Every collection includes these default fields:
140-
141-
- `id`: Unique content identifier
142-
- `stem`: File path without extension (used for sorting and location)
143-
- `extension`: File extension
144-
- `meta`: Custom fields not defined in the collection schema
145-
146-
Additional fields for `page` type collections:
147-
148-
- `path`: Generated route path
149-
- `title`: Page title
150-
- `description`: Page description
151-
- `seo`: SEO metadata (to be used with Nuxt's `useSeoMeta` composable)
152-
- `body`: Page content parsed as AST
153-
- `navigation`: Page navigation configuration (for [`queryCollectionNavigation](/docs/composables/query-collection-navigation))
154-
155-
### Returns
138+
::note{to="/docs/usage/sources"}
139+
Learn more about collection sources.
140+
::
156141
157142
The function returns the defined collection object.

docs/content/docs/2.usage/2.types.md renamed to docs/content/docs/2.collections/2.types.md

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
---
2-
title: Collection types
2+
title: Types
33
description: Learn about the two types of collections you can define in Nuxt Content.
44
---
55

66
In Nuxt Content, you can specify a type for each collection, depending on the intended purpose of the collection files. Collections can be defined as either **page** or **data** types.
77

8+
For both types, built-in fields are generated. Every collection includes these default fields:
9+
10+
- `id`: Unique content identifier
11+
- `stem`: File path without extension (used for sorting and location)
12+
- `extension`: File extension
13+
- `meta`: Custom fields not defined in the collection schema
14+
815
## Page type
916

1017
```ts
@@ -14,7 +21,9 @@ defineCollection({
1421
})
1522
```
1623

24+
::tip
1725
Use the **page** type if there is a 1-to-1 relationship between content files and pages on your site.
26+
::
1827

1928
### Path generation
2029

@@ -30,20 +39,26 @@ Here are examples of generated paths based on file structure:
3039
| `content/blog/hello.md` | `/blog/hello` |
3140
| `content/1.guide/2.installation` | `/guide/installation` |
3241

33-
42+
::note
3443
You can use the helper [`queryCollection('COLLECTION').path('PATH')`{lang=ts}](/composables/query-collection) to retrieve content by a specific path.
44+
::
3545

3646
### Schema Overrides
3747

3848
When you use the **page** type, Nuxt Content generates several standard fields that are commonly used for web pages. These fields provide structure and are **automatically** applied to the collection’s schema:
49+
50+
- `path`: Generated route path
51+
- `title`: Page title
52+
- `description`: Page description
53+
- `seo`: SEO metadata (to be used with Nuxt's `useSeoMeta` composable)
54+
- `body`: Page content parsed as AST
55+
- `navigation`: Page navigation configuration (for [queryCollectionNavigation](/docs/composables/query-collection-navigation))
56+
57+
Here is the corresponding schema applied:
3958
```ts
40-
// Generated path of your file
4159
path: z.string(),
42-
// Title of your page
4360
title: z.string(),
44-
// Description of your page
4561
description: z.string(),
46-
// Seo information
4762
seo: z.intersection(
4863
z.object({
4964
title: z.string().optional(),
@@ -53,13 +68,11 @@ When you use the **page** type, Nuxt Content generates several standard fields t
5368
}),
5469
z.record(z.string(), z.any()),
5570
).optional().default({}),
56-
// AST of your markdown parsed (only useful for Markdown files)
5771
body: z.object({
5872
type: z.string(),
5973
children: z.any(),
6074
toc: z.any(),
6175
}),
62-
// Navigation information
6376
navigation: z.union([
6477
z.boolean(),
6578
z.object({
@@ -74,9 +87,26 @@ When you use the **page** type, Nuxt Content generates several standard fields t
7487
You can override any of these fields by defining them in the collection’s schema.
7588
::
7689

77-
### Ordering Files
90+
## Data type
7891

79-
Since each file corresponds to a page, you may want to control the display order in lists. Use numeric prefixes in file and directory names to specify an order. Nuxt Content will use these numbers when ordering content lists.
92+
```ts
93+
defineCollection({
94+
source: 'authors/**.yml',
95+
type: 'data'
96+
})
97+
```
98+
99+
The data type is useful for content that doesn’t directly correspond to a webpage but instead represents structured data you might want to query and display within your application.
100+
101+
With data collections, you have complete control over the schema, allowing you to define custom structures.
102+
103+
::note
104+
There’s no strict relationship between collection type and file extension. For instance, a **page** collection can use [Markdown](/docs/usage/markdown) or [YAML](/docs/usage/yaml) or JS[Markdown](/docs/usage/json) files, and **data** collections can use any of these formats as well.
105+
::
106+
107+
## Ordering Files
108+
109+
For both types, you may want to control the display order in lists. Use numeric prefixes in file and directory names to specify an order. Nuxt Content will use these numbers when ordering content lists.
80110

81111
``` [Directory structure]
82112
content/
@@ -94,19 +124,3 @@ content/
94124
Separate number from file name using `.` character. Using any other separator will not work.
95125
::
96126

97-
## Data type
98-
99-
```ts
100-
defineCollection({
101-
source: 'authors/**.yml',
102-
type: 'data'
103-
})
104-
```
105-
106-
The data type is useful for content that doesn’t directly correspond to a webpage but instead represents structured data you might want to query and display within your application.
107-
108-
With data collections, you have complete control over the schema, allowing you to define custom structures.
109-
110-
::note
111-
There’s no strict relationship between collection type and file extension. For instance, a **page** collection can use [Markdown](/docs/usage/markdown) or [YAML](/docs/usage/yaml) or JS[Markdown](/docs/usage/json) files, and **data** collections can use any of these formats as well.
112-
::
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: Sources
3+
description: Learn how to import your files in Nuxt Content collections.
4+
---
5+
6+
Nuxt Content provides several ways to import content files into your collection. You can configure the source by using the `source` property within `defineCollection`:
7+
8+
```ts [content.config.ts]
9+
import { defineCollection } from '@nuxt/content'
10+
11+
export const collections = {
12+
docs: defineCollection({
13+
source: '**',
14+
type: 'page'
15+
})
16+
}
17+
```
18+
19+
## `source`
20+
21+
The `source` property can be defined as either a string (following a glob pattern) or an object, allowing more detailed source configuration for your target directory and files within the content folder.
22+
23+
**Example:**
24+
- `source: '**` includes all files within the content directory and its subdirectories.
25+
- `source: '**/*.md'`includes all `Markdown` files within the content directory and its subdirectories.
26+
- `source: 'docs/**/*.yml'` includes all `YML` files within the `content/docs` and its subdirectories.
27+
- `source: '**/*.{json,yml}'` includes `JSON` or `YML` file within the content directory and all its subdirectories.
28+
- `source: '*.json'` includes only `JSON` files located directly within the content directory, excluding any subdirectories.
29+
30+
### `include`
31+
32+
Glob pattern of your target repository and files in the content folder.
33+
34+
### `exclude`
35+
36+
Glob patterns to exclude content from the import.
37+
38+
### `prefix`
39+
40+
This configuration only applied for **page** type with 1-to-1 relationship between content files and pages on your site.
41+
42+
It represents the path prefix (base URL) of the corresponding page on the website.
43+
44+
### `cwd`
45+
46+
Root directory for content matching.
47+
48+
### `repository`
49+
50+
External source representing a remote git repository URL (e.g., https://github.com/nuxt/content)

docs/content/docs/2.usage/.navigation.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
title: Files
3+
icon: i-lucide-file

0 commit comments

Comments
 (0)