Skip to content

Commit d201414

Browse files
committed
docs: update structure
1 parent b636587 commit d201414

File tree

14 files changed

+148
-96
lines changed

14 files changed

+148
-96
lines changed

docs/content/docs/1.getting-started/2.installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const collections = {
5252
}
5353
```
5454

55-
This configuration creates a default `content` collection that processes all Markdown files in your project. You can customize the collection settings based on your needs.
55+
This configuration creates a default `content` collection that processes all Markdown files located in the `content` folder of your project. You can customize the collection settings based on your needs.
5656

5757
::tip
5858
The `type: page` setting specifies that each file in the collection represents a [Markdown page](/docs/usage/markdown).
File renamed without changes.

docs/content/docs/1.getting-started/5.configuration.md renamed to docs/content/docs/1.getting-started/4.configuration.md

File renamed without changes.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
title: Concepts
1+
2+
title: Key Concepts
23
icon: i-lucide-lightbulb

docs/content/docs/1.getting-started/3.collections.md renamed to docs/content/docs/2.usage/1.collections.md

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

6+
The Nuxt Content module automatically parses any content files within the `content` directory located at the root of your Nuxt application. This setup allows you to freely structure the folder to suit your project's needs. For a better organization, consider using Content Collections, which let you categorize and manage content more effectively. These collections are defined in a `content.config.ts` file.
7+
8+
::warning
9+
If no `content.config.ts` file is present, all files within the content folder are parsed and imported by default. However, once a config file is added, only files matching the specified path patterns defined in collections will be imported.
10+
::
11+
12+
613
## What are Content Collections?
714

815
Content Collections organize related items within your Nuxt Content project. They provide a structured way to manage your content, making it easier to query, display, and maintain your site's data.
@@ -34,8 +41,9 @@ export const collections = {
3441
}
3542
```
3643

37-
::note{to="#collection-types"}
38-
Learn more about the different types of collections.
44+
45+
::note{to="/usage/types"}
46+
Learn more about collection types.
3947
::
4048

4149
### Collection Schema
@@ -61,30 +69,13 @@ export const collections = {
6169
}
6270
```
6371

64-
::tip
65-
`@nuxt/content` exposes a `z` object that contains a set of Zod schemas for common data types.
72+
::note
73+
`@nuxt/content` exposes a `z` object that contains a set of Zod schemas for common data types. Check the [Zod’s README](https://github.com/colinhacks/zod) for complete documentation on how Zod works and what features are available.
6674
::
6775

68-
### Multiple Collections
69-
70-
You can define multiple collections to organize different types of content:
71-
72-
```ts [content.config.ts]
73-
import { defineCollection, z } from '@nuxt/content'
74-
75-
export const collections = {
76-
blog: defineCollection({
77-
// Load top-level Markdown files from content/blog
78-
source: 'blog/*.md',
79-
type: 'page'
80-
}),
81-
docs: defineCollection({
82-
// Load all Markdown files from content/docs
83-
source: 'docs/**.md',
84-
type: 'page'
85-
})
86-
}
87-
```
76+
::tip
77+
You can define as many collections as you want to organize different types of content.
78+
::
8879

8980
## Querying Collections
9081

@@ -141,12 +132,6 @@ type CollectionSource = {
141132
}
142133
```
143134
144-
### Collection Types
145-
146-
The `type` parameter determines content processing:
147-
- `data`: For structured data files (JSON, YAML) that don't require rendering
148-
- `page`: For full pages with layouts and components that need rendering
149-
150135
### Built-in Fields
151136
152137
Every collection includes these default fields:

docs/content/docs/2.usage/1.source.md

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
title: Collection types
3+
description: Learn about the two types of collections you can define in Nuxt Content.
4+
---
5+
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+
8+
## Page type
9+
10+
```ts
11+
defineCollection({
12+
source: '**.md',
13+
type: 'page'
14+
})
15+
```
16+
17+
Use the **page** type if there is a 1-to-1 relationship between content files and pages on your site.
18+
19+
### Path generation
20+
21+
Nuxt Content will automatically generate a path for each file in the collection, making it easy to create URL mappings.
22+
23+
Here are examples of generated paths based on file structure:
24+
25+
| File | Path |
26+
| -------------------------------- | :-------------------- |
27+
| `content/index.md` | `/` |
28+
| `content/about.md` | `/about` |
29+
| `content/blog/index.md` | `/blog` |
30+
| `content/blog/hello.md` | `/blog/hello` |
31+
| `content/1.guide/2.installation` | `/guide/installation` |
32+
33+
34+
You can use the helper [`queryCollection('COLLECTION').path('PATH')`{lang=ts}](/composables/query-collection) to retrieve content by a specific path.
35+
36+
### Schema Overrides
37+
38+
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:
39+
```ts
40+
// Generated path of your file
41+
path: z.string(),
42+
// Title of your page
43+
title: z.string(),
44+
// Description of your page
45+
description: z.string(),
46+
// Seo information
47+
seo: z.intersection(
48+
z.object({
49+
title: z.string().optional(),
50+
description: z.string().optional(),
51+
meta: z.array(z.record(z.string(), z.any())).optional(),
52+
link: z.array(z.record(z.string(), z.any())).optional(),
53+
}),
54+
z.record(z.string(), z.any()),
55+
).optional().default({}),
56+
// AST of your markdown parsed (only useful for Markdown files)
57+
body: z.object({
58+
type: z.string(),
59+
children: z.any(),
60+
toc: z.any(),
61+
}),
62+
// Navigation information
63+
navigation: z.union([
64+
z.boolean(),
65+
z.object({
66+
title: z.string(),
67+
description: z.string(),
68+
icon: z.string(),
69+
}),
70+
]).default(true),
71+
```
72+
73+
::note
74+
You can override any of these fields by defining them in the collection’s schema.
75+
::
76+
77+
### Ordering Files
78+
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.
80+
81+
``` [Directory structure]
82+
content/
83+
1.frameworks/
84+
1.vue.md
85+
2.nuxt.md
86+
2.examples/
87+
1.vercel.md
88+
2.netlify.md
89+
3.heroku.md
90+
index.md
91+
```
92+
93+
::warning
94+
Separate number from file name using `.` character. Using any other separator will not work.
95+
::
96+
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](/usage/markdown) or [YAML](/usage/yaml) or JS[Markdown](/usage/json) files, and **data** collections can use any of these formats as well.
112+
::
Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ title: Markdown Pages
33
description: "Nuxt Content uses the Markdown syntax and conventions to provide a rich-text editing experience."
44
---
55

6-
76
## Define Collection
87

98
```ts [content.config.ts]
@@ -16,12 +15,11 @@ export const collections = {
1615
})
1716
})
1817
}
19-
2018
```
2119

2220
## Create `.md` files
2321

24-
Create authors files in `content/blog/` directory.
22+
Create blog posts in `content/blog/` directory.
2523

2624
::code-group
2725
```md [foo.md]
@@ -48,19 +46,19 @@ Now we can query blog posts:
4846

4947
```ts
5048
// Find a foo post
51-
const theAuthor = await queryCollection('blog')
49+
const fooPost = await queryCollection('blog')
5250
.path('/foo')
5351
.first()
5452

5553
// Get all posts
56-
const post = await queryCollection('blog')
54+
const allPosts = await queryCollection('blog')
5755
.order('date', 'DESC')
5856
.all()
5957
```
6058

6159
## MDC Syntax
6260

63-
We created the MDC syntax to supercharge Markdown and give you the ability to leverage the power of Vue components with slots and props.
61+
We created the MDC syntax to supercharge Markdown and give you the ability to integrate Vue components with slots and props inside your Markdown.
6462

6563
::callout
6664
Install the [MDC VS Code extension](https://marketplace.visualstudio.com/items?itemName=Nuxt.mdc) to get proper syntax highlighting for your MDC components.
@@ -70,7 +68,7 @@ Install the [MDC VS Code extension](https://marketplace.visualstudio.com/items?i
7068

7169
Front-matter is a convention of Markdown-based CMS to provide meta-data to pages, like description or title. In Nuxt Content, the front-matter uses the YAML syntax with `key: value` pairs.
7270

73-
These data are available when rendering the content and can hold any information that you would need.
71+
These data are available when rendering the content and can store any information that you would need.
7472

7573
#### Syntax
7674

@@ -159,7 +157,7 @@ And then use them in your markdown files in the `content` directory as such:
159157

160158
Every Vue component created inside the `components/content/` directory will be available in Markdown files.
161159

162-
::callout{ type="info"}
160+
::warning
163161
Components that are used in Markdown has to be marked as `global` in your Nuxt app if you don't use the `components/content/` directory, visit [Nuxt 3 docs](https://nuxt.com/docs/guide/directory-structure/components) to learn more about it.
164162
::
165163

@@ -195,10 +193,9 @@ In a markdown file, use the component with the **`::`** identifier.
195193
The content of the card
196194
::
197195
::
198-
199196
::
200197

201-
##### Slots
198+
#### Slots
202199

203200
A component's slots can accept content or another components.
204201

@@ -234,7 +231,7 @@ A component's slots can accept content or another components.
234231
::
235232
::
236233

237-
##### Nesting
234+
#### Nesting
238235

239236
MDC supports nested components inside slots by indenting them.
240237

@@ -243,9 +240,9 @@ MDC supports nested components inside slots by indenting them.
243240
::hero
244241
:::card
245242
A nested card
246-
::card
243+
::::card
247244
A super nested card
248-
::
245+
::::
249246
:::
250247
::
251248
```
@@ -260,11 +257,11 @@ MDC supports nested components inside slots by indenting them.
260257
::
261258
::
262259

263-
::callout{type="info"}
260+
::note
264261
You can add more `::::` when nesting components as a visual reminder.
265262
::
266263

267-
##### Markdown rendering
264+
#### Markdown rendering
268265

269266
The `<MDCSlot />`{lang="html"} component is auto-imported by Nuxt Content. It acts as a special slot that accepts rich text rendered by Markdown.
270267

@@ -334,7 +331,7 @@ In this example, `:hello{}` will search for the `<Hello />` component, and `-wor
334331

335332
There are two ways to pass props to components using MDC.
336333

337-
##### Inline method
334+
#### Inline method
338335

339336
The `{}` identifier passes props to components in a terse way by using a `key=value` syntax.
340337

@@ -404,7 +401,7 @@ Note that in this case you should use single quotes for the value string so you
404401
```
405402
::
406403

407-
##### YAML method
404+
#### YAML method
408405

409406
The YAML method uses the `---` identifier to declare one prop per line, that can be useful for readability.
410407

File renamed without changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
icon: i-lucide-code-xml
2+
title: Advanced Concepts

0 commit comments

Comments
 (0)