You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/docs/2.collections/2.types.md
+40-26Lines changed: 40 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,17 @@
1
1
---
2
-
title: Collection types
2
+
title: Types
3
3
description: Learn about the two types of collections you can define in Nuxt Content.
4
4
---
5
5
6
6
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.
7
7
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
+
8
15
## Page type
9
16
10
17
```ts
@@ -14,7 +21,9 @@ defineCollection({
14
21
})
15
22
```
16
23
24
+
::tip
17
25
Use the **page** type if there is a 1-to-1 relationship between content files and pages on your site.
26
+
::
18
27
19
28
### Path generation
20
29
@@ -30,20 +39,26 @@ Here are examples of generated paths based on file structure:
You can use the helper [`queryCollection('COLLECTION').path('PATH')`{lang=ts}](/composables/query-collection) to retrieve content by a specific path.
44
+
::
35
45
36
46
### Schema Overrides
37
47
38
48
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)
@@ -53,13 +68,11 @@ When you use the **page** type, Nuxt Content generates several standard fields t
53
68
}),
54
69
z.record(z.string(), z.any()),
55
70
).optional().default({}),
56
-
// AST of your markdown parsed (only useful for Markdown files)
57
71
body: z.object({
58
72
type: z.string(),
59
73
children: z.any(),
60
74
toc: z.any(),
61
75
}),
62
-
// Navigation information
63
76
navigation: z.union([
64
77
z.boolean(),
65
78
z.object({
@@ -74,9 +87,26 @@ When you use the **page** type, Nuxt Content generates several standard fields t
74
87
You can override any of these fields by defining them in the collection’s schema.
75
88
::
76
89
77
-
### Ordering Files
90
+
##Data type
78
91
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.
80
110
81
111
```[Directory structure]
82
112
content/
@@ -94,19 +124,3 @@ content/
94
124
Separate number from file name using `.` character. Using any other separator will not work.
95
125
::
96
126
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.
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
+
exportconst 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)
0 commit comments