Skip to content

Commit d936c48

Browse files
committed
docs: improvements
1 parent 56fdfd3 commit d936c48

File tree

7 files changed

+132
-83
lines changed

7 files changed

+132
-83
lines changed
Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,44 @@
11
---
22
navigation.title: Introduction
33
title: Nuxt Content v3
4-
description: Nuxt Content version 3 is the last version of the Git-based CMS designed for Nuxt developers.
4+
description: The powerful Git-based CMS designed specifically for Nuxt developers.
55
---
66

7-
We’re excited to announce Nuxt Content v3, a major upgrade with enhanced performance and new features. As the latest iteration of our Git-based CMS, Nuxt Content v3 is optimized for modern applications built with Nuxt.
7+
Welcome to Nuxt Content v3, a major upgrade that brings enhanced performance and innovative features to your Nuxt projects. This latest iteration of our Git-based CMS is optimized for modern application development.
88

99
## What's New?
1010

1111
### Content Collections
1212

13-
Collections are groups of related content items within your Nuxt Content project. They help organize and manage large datasets more efficiently, introducing a host of benefits:
13+
Collections organize related items within your project, helping you manage large datasets more efficiently. Key benefits include:
1414

15-
- **Define Collections**: Configure database structures and define your collections in the `content.config.ts` file.
16-
- **Type-safe Queries**: Optimal Typescript integration with all Nuxt Content utilities.
17-
- **Automatic Validation**: Validate frontmatter fields or data files (json, yml...) to ensure data consistency and accuracy.
18-
- **Powerful Query Builder**: Use the query builder to filter, sort, and paginate your content collections.
19-
- **Studio Integration**: Collections empower the [Studio](https://nuxt.studio), enhancing form generation and ensuring the best editing experience on the platform.
15+
- **Structured Data**: Configure database architecture and define collections in [`content.config.ts`](/getting-started/collections#defining-collections)
16+
- **Type-safe Queries**: Direct TypeScript integration across all utilities
17+
- **Automatic Validation**: Ensure data consistency across frontmatter fields and data files (json, yml...)
18+
- **Advanced Query Builder**: Filter, sort, and paginate your collections with ease
19+
- **Studio Integration**: Enhanced form generation and optimal editing experience through [Studio](https://nuxt.studio)
2020

21-
Read more about [Content Collections](/getting-started/collections).
21+
Learn more about [Content Collections](/getting-started/collections).
2222

23-
### Improved Performance with SQL Storage
23+
### Improved Performance
2424

25-
A key challenge with Nuxt Content v2 was the large bundle size required to store all content files. It was mainly an issue when deploying to edge platforms like [NuxtHub](https://hub.nuxt.com/).
25+
A significant challenge in v2 was the large bundle size needed for storing files, particularly affecting serverless deployments.
2626

27-
To address this, Nuxt Content v3 moves away from the file based storing in production and leverage SQL database system. This switch is transparent to users. We provide a zero config support for development mode, static generation, server rendering and edge deployments offering:
27+
V3 addresses this by transitioning to SQL-based storage in production. This switch requires zero configuration, supporting development mode, static generation, server hosting, serverless and edge deployments.
2828

29-
- **Optimized Queries**: SQL storage enables ultra-fast querying, improving both performance and scalability.
30-
- **Flexible Compatibility:** With an adapter-based system, Nuxt Content v3 easily integrates SQL databases without configuration, regardless of deployment mode (static, server-side, SPA, edge) or platform. For more details, see our [platform deployment options](/deploy/node). We're also inviting community contributions to support additional adapters.
29+
Benefits include:
3130

31+
- **Optimized Queries**: SQL storage enables ultra-fast data retrieval
32+
- **Universal Compatibility**: Our adapter-based system integrates SQL databases across all deployment modes (static, server-side, SPA, edge) and platforms. See our [platform deployment options](/deploy/node) for details. We welcome community contributions for additional adapters.
3233

3334
### TypeScript Integration
3435

35-
With help of the new collections system, the module provides automatic Typescript types for all your contents.
36+
The new collections system provides automatic TypeScript types for all your data. Every utility and API is strongly typed based on your collection definitions, ensuring robust type safety throughout development.
3637

37-
All utilities and APIs within the module are strongly typed based on the definitions in your collections, ensuring type safety and reducing errors during development.
38+
### Nuxt Studio Integration :badge[Soon]{color=neutral}
3839

39-
### Built with Nuxt Studio in mind
40-
41-
[Nuxt Studio](https://nuxt.studio) was originally developed alongside Nuxt Content v2, but with v3, we're building the module with the Studio experience in mind. This is why we are providing a tighter integration with Nuxt Studio as our goal is to create the best CMS platform for content editing, while still offering the best developers experience.
42-
43-
The [studio module](https://github.com/nuxtlabs/studio-module) will now be part of Nuxt Content itself. We want the developer to focus on code and let the non technical collaborators edit the content with an intuitive interface.
40+
[Nuxt Studio](https://nuxt.studio) and v3 are designed to complement each other perfectly. The [studio module](https://github.com/nuxtlabs/studio-module) is now integrated directly into Nuxt Content, creating an ideal environment where developers can focus on code while team members manage content through an intuitive interface.
4441

4542
:hr
4643

47-
We're excited about the possibilities Nuxt Content v3 brings to your projects. Explore our documentation to learn more about the module integration and all the best practices for building your next website.
44+
We're excited for you to explore these new capabilities. Dive into our documentation to learn more about integrating the module and implementing best practices in your next project.

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: Installation
3-
description: 'Learn how to install and configure Nuxt Content v3 in your application.'
3+
description: 'Get started with Nuxt Content v3 in your Nuxt application.'
44
---
55

6-
## Setup
6+
### Install the Package
77

8-
1. Install the Nuxt Content v3 alpha package:
8+
Choose your preferred package manager to install Nuxt Content v3:
99

1010
::code-group
1111

@@ -27,15 +27,19 @@ bun add @nuxt/content@next
2727

2828
::
2929

30-
2. Register the Nuxt Content module in your `nuxt.config.ts`{lang="ts-type"}:
30+
### Register the Module
31+
32+
Add the Nuxt Content module to your `nuxt.config.ts`:
3133

3234
```ts [nuxt.config.ts]
3335
export default defineNuxtConfig({
3436
modules: ['@nuxt/content']
3537
})
3638
```
3739

38-
3. Create `content.config.ts` file in project root directory and create your first collextion.
40+
### Create your First Collection
41+
42+
Create a `content.config.ts` file in your project root directory:
3943

4044
```ts [content.config.ts]
4145
import { defineCollection } from '@nuxt/content'
@@ -46,4 +50,16 @@ export const collections = {
4650
source: '**/*.md'
4751
})
4852
}
49-
```
53+
```
54+
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.
56+
57+
::tip
58+
The `type: page` setting specifies that each file in the collection represents a [Markdown page](/usage/markdown).
59+
::
60+
61+
::note{to="/getting-started/collections"}
62+
Learn more in our **Collections guide**.
63+
::
64+
65+
Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,32 @@
11
---
2-
title: 'Collections'
3-
description: 'How to define and configue content collections.'
4-
navigation:
5-
title: Content Collections
2+
title: 'Content Collections'
3+
description: 'Learn how to define and configure content collections in your Nuxt application.'
64
---
75

8-
Collections in Nuxt Content are a powerful way to organize and manage your content. They allow you to group related content items together, making it easier to query, display, and maintain your site's content.
9-
10-
116
## What are Content Collections?
127

13-
Content Collections are groups of related content items within your Nuxt Content project. They provide a structured way to organize and manage your content, making it easier to work with large amounts of data.
14-
15-
Key features of Content Collections include:
16-
17-
1. **Logical Grouping**: Collections allow you to group similar content together, such as blog posts, product pages, or documentation articles.
18-
19-
2. **Shared Configuration**: You can apply common settings and validations to all items within a collection, ensuring consistency across your content.
20-
21-
3. **Improved Querying**: Collections make it easier to fetch and filter related content items, enhancing the performance and flexibility of your content queries.
8+
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.
229

23-
4. **Automatic Type Inference**: Nuxt Content can automatically infer the structure of your content, providing type safety and autocompletion in your development environment.
10+
Key features include:
2411

25-
5. **Flexible Structure**: Collections can be organized in various ways, such as by content type, category, or any other logical grouping that suits your project's needs.
12+
- **Logical Grouping**: Group similar content together, such as blog posts, product pages, or documentation articles
13+
- **Shared Configuration**: Apply common settings and validations across all items within a collection
14+
- **Improved Querying**: Fetch and filter related content items efficiently
15+
- **Automatic Type Inference**: Get type safety and autocompletion in your development environment
16+
- **Flexible Structure**: Organize collections by content type, category, or any other logical grouping that suits your needs
2617

2718
## Defining Collections
2819

29-
To define a custom collection, create `content.config.ts` file in ptoject's root directory. This is a special file that Nuxt Content will load and use to configure collections database, utility types and finding/parsing/querying contents.
20+
Create a `content.config.ts` file in your project's root directory. This special file configures your collections database, utility types, and content handling.
3021

31-
Here's a simple example of how to define collections in your `content.config.ts` file:
22+
Here's a basic example:
3223

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

36-
// Export collections
3727
export const collections = {
38-
// Define collection using `defineCollection` utility
3928
docs: defineCollection({
40-
// Define the source directory for the collection
41-
// `source: '**'` will load every file inside `content` directory
29+
// Load every file inside the `content` directory
4230
source: '**',
4331
// Specify the type of content in this collection
4432
type: 'page'
@@ -48,24 +36,19 @@ export const collections = {
4836

4937
### Collection Schema
5038

51-
Schema is and important part of each collection. Schemas enforce consistent data within a collection. Schemas also are grounf truth of Typescript typings for collections.
39+
Schemas enforce data consistency within a collection and serve as the source of truth for TypeScript types.
5240

53-
To define schema for you collection, go to `content.config.ts` and provide `schema` for your collection in `defineCollection` function.
41+
Define a schema by adding the `schema` property to your collection by using a [`zod`](https://zod.dev) schema:
5442

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

58-
// Export collections
5946
export const collections = {
60-
// Define collection using `defineCollection` utility
6147
docs: defineCollection({
62-
// Define the source directory for the collection
63-
// `source: '**'` will load every file inside `content` directory
64-
source: '**',
65-
// Specify the type of content in this collection
48+
source: '**.md',
6649
type: 'page',
6750
// Define custom schema for docs collection
68-
schema: z.object({ // Schema root should be an object!!
51+
schema: z.object({ // Schema must be an object
6952
tags: z.array(z.string()),
7053
image: z.string(),
7154
date: z.Date()
@@ -74,41 +57,52 @@ export const collections = {
7457
}
7558
```
7659

60+
::tip
61+
`@nuxt/content` exposes a `z` object that contains a set of Zod schemas for common data types.
62+
::
7763

78-
### Multiple collections
79-
80-
Defining multiple collections is as easy as creating one.
64+
### Multiple Collections
8165

66+
You can define multiple collections to organize different types of content:
8267

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

86-
// Export collections
8771
export const collections = {
88-
// Define collection using `defineCollection` utility
8972
blog: defineCollection({
90-
// Define the source directory for the collection
91-
// `source: 'blog/**'` will load every file inside `content/blog` directory
92-
source: 'blog/**',
93-
// Specify the type of content in this collection
73+
// Load top-level Markdown files from content/blog
74+
source: 'blog/*.md',
9475
type: 'page'
9576
}),
9677
docs: defineCollection({
97-
// Define the source directory for the collection
98-
// `source: 'docs/**'` will load every file inside `content/docs` directory
99-
source: 'docs/**',
100-
// Specify the type of content in this collection
78+
// Load all Markdown files from content/docs
79+
source: 'docs/**.md',
10180
type: 'page'
10281
})
10382
}
10483
```
10584

10685
## Querying Collections
10786

108-
Nuxt Content provides `queryCollection` utility to query a collection and fetch on or all contents.
109-
110-
```ts
111-
const docs = await queryCollection('docs').all()
87+
Use the [`queryCollection`](/api/query-collection) util to fetch one or all items from a collection:
88+
89+
```vue [pages/blog.vue]
90+
<script setup lang="ts">
91+
const { data: posts } = await useAsyncData('blog', () => queryCollection('blog').all())
92+
</script>
93+
94+
<template>
95+
<div>
96+
<h1>Blog</h1>
97+
<ul>
98+
<li v-for="post in posts" :key="post._id">
99+
<NuxtLink :to="post.path">{{ post.title }}</NuxtLink>
100+
</li>
101+
</ul>
102+
</div>
103+
</template>
112104
```
113105

114-
Checkout [`queryCollections` API](/api/query-collection).
106+
::note{to="/api/query-collection"}
107+
Learn more about the available query options in our `queryCollections` API documentation.
108+
::

docs/content/1.getting-started/5.migration.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Here is the list breaking changes in Content v3:
2323
- `<ContentDoc>`, `<ContentList>`, `<ContentNavigation>` and `<ContentQuery>` components are dropped in v3.
2424
- `_dir.yml` files are renamed to `.navigation.yml`
2525
- Multi source is dropped in favor of multi collection.
26+
- Document `._path` is now renamed to `.path`
2627
- `searchContent()`{lang=ts} is dropped in favor of new api `queryCollectionSearchSections`
2728
- Full text search can easily done using this API See [Full-Text Search Snippets](/snippets/fulltext-search)
2829
- `useContentHelpers()`{lang=ts} is removed
@@ -59,8 +60,6 @@ As we mentioned above, `queryContent` is droped in favor of new collection based
5960
1. `queryCollection` is builting a query for SQL database.
6061
2. `queryCollection` do the search only inside the specific collection. You should know the collection.
6162

62-
63-
6463
```ts [Find content with path]
6564
// Content v2
6665
const v2Query = await queryContent(route.path).findOne()

docs/content/5.deploy/2.nuxthub.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: NuxtHub
3+
description: How to deploy Nuxt Content to NuxtHub.
4+
navigation:
5+
icon: i-simple-icons-nuxtdotjs
6+
---
7+
8+
Nuxt Content uses Nuxt deployment presets to adjust the build process for different hosting platforms. To deploy your Nuxt Content to Cloudflare, you can use the `cloudflare_pages`{lang="ts-type"} preset.
9+
10+
You can do that in two ways:
11+
12+
- By defining the `NITRO_PRESET`{lang="ts-type"} to `cloudflare_pages`{lang="ts-type"} when running the build process, like so:
13+
14+
```bash
15+
NITRO_PRESET=cloudflare_pages npm run build
16+
```
17+
18+
Or by updating your Nuxt configuration:
19+
20+
```bash
21+
"preset": "cloudflare_pages",
22+
```
23+
24+
If you use the [Cloudflare Pages GitHub/GitLab integration][1]{target="_blank"} Nuxt does not require configuration for presets.
25+
26+
## Database
27+
28+
Unfortunately sqlite database is not supported in cloudflare environment and you should use another database.
29+
You can simply create a D1 database in cloudflare and use Content Module's D1 adapter.
30+
31+
- You can simply use [Nuxt Hub][nuxt-hub] to create, connect and manage D1 database for you.
32+
- Or you can create it directly create a D1 database from Cloudflare dashboard and connect it to you project by creating a `wrangler.toml` file in project root. [Get started with Cloudflare D1][d1]
33+
34+
35+
36+
37+
38+
39+
40+
41+
[1]: https://developers.cloudflare.com/pages/get-started/#connect-your-git-provider-to-pages
42+
[nuxt-hub]: https://hub.nuxt.com/docs/features/database
43+
[d1]: https://developers.cloudflare.com/d1/get-started/

examples/blog/app/pages/[...slug].vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const { data: post } = await useAsyncData(() => {
1010
<template>
1111
<div>
1212
<nuxt-link to="/">
13-
<small>«Back </small>
13+
<small Back </small>
1414
</nuxt-link>
1515
<h1>{{ post.title }}</h1>
1616
<ContentRenderer :value="post" />

src/utils/dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export async function watchContents(nuxt: Nuxt, options: ModuleOptions, manifest
5555
async function onChange(path: string) {
5656
const collection = localCollections.find(({ source }) => micromatch.isMatch(path, source!.path, { ignore: source!.ignore || [], dot: true }))
5757
if (collection) {
58-
logger.info(`File changed. collection: ${collection.name}, path: ${path}`)
58+
logger.info(`File \`${path}\` changed on \`${collection.name}\` collection`)
5959

6060
const { fixed } = parseSourceBase(collection.source!)
6161
const keyInCollection = join(collection.name, collection.source?.prefix || '', path.replace(fixed, ''))

0 commit comments

Comments
 (0)