Skip to content

Commit

Permalink
docs: update
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed Nov 7, 2024
1 parent 0d2c690 commit 1dac4d5
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 165 deletions.
68 changes: 65 additions & 3 deletions docs/content/docs/1.getting-started/3.collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ export const collections = {
}
```

::note{to="#collection-types"}
Learn more about the different types of collections.
::

### Collection Schema

Schemas enforce data consistency within a collection and serve as the source of truth for TypeScript types.

Define a schema by adding the `schema` property to your collection by using a [`zod`](https://zod.dev) schema:
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'
Expand All @@ -48,7 +52,7 @@ export const collections = {
source: '**.md',
type: 'page',
// Define custom schema for docs collection
schema: z.object({ // Schema must be an object
schema: z.object({
tags: z.array(z.string()),
image: z.string(),
date: z.Date()
Expand Down Expand Up @@ -84,7 +88,7 @@ export const collections = {

## Querying Collections

Use the [`queryCollection`](/docs/composables/query-collection) util to fetch one or all items from a collection:
Use the [`queryCollection`](/docs/utils/query-collection) util to fetch one or all items from a collection:

```vue [pages/blog.vue]
<script setup lang="ts">
Expand All @@ -106,3 +110,61 @@ const { data: posts } = await useAsyncData('blog', () => queryCollection('blog')
::note{to="/api/query-collection"}
Learn more about the available query options in our `queryCollections` API documentation.
::

## defineCollection()

The `defineCollection` function defines a collection in your content configuration. Here's its TypeScript signature:

```ts
function defineCollection(collection: Collection): DefinedCollection

type Collection = {
// Determines how content is processed
type: 'page' | 'data'
// Specifies content location
source?: string | CollectionSource
// Zod schema for content validation and typing
schema?: ZodObject<T>
}

type CollectionSource = {
// Glob pattern for content matching
include: string
// .path prefix (only applies to 'page' type)
prefix?: string
// Glob patterns to exclude content
exclude?: string[]
// Root directory for content matching
cwd?: string
// Remote git repository URL (e.g., https://github.com/nuxt/content)
repository?: string
}
```
### Collection Types
The `type` parameter determines content processing:
- `data`: For structured data files (JSON, YAML) that don't require rendering
- `page`: For full pages with layouts and components that need rendering
### Built-in Fields
Every collection includes these default fields:
- `_id`: Unique content identifier
- `stem`: File path without extension (used for sorting and location)
- `extension`: File extension
- `meta`: Custom fields not defined in the collection schema
Additional fields for `page` type collections:
- `path`: Generated route path
- `title`: Page title
- `description`: Page description
- `seo`: SEO metadata (to be used with Nuxt's `useSeoMeta` composable)
- `body`: Page content parsed as AST
- `navigation`: Page navigation configuration (for [`queryCollectionNavigation](/docs/composables/query-collection-navigation))

### Returns

The function returns the defined collection object.
116 changes: 0 additions & 116 deletions docs/content/docs/3.composables/10.defineCollection.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
icon: i-lucide-square-function
title: Vue Utils
2 changes: 1 addition & 1 deletion docs/content/docs/4.components/0.content-renderer.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: ContentRenderer
description: 'Takes your component from an AST to a wonderful template.'
---

The `<ContentRenderer>` component renders a document coming from a query with [`queryCollections()`](/docs/composables/query-collection).
The `<ContentRenderer>` component renders a document coming from a query with [`queryCollections()`](/docs/utils/query-collection).

> This component works only with `pages` collections.
Expand Down
14 changes: 6 additions & 8 deletions docs/content/docs/5.deploy/1.cloudflare.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ If you use the [Cloudflare Pages GitHub/GitLab integration][1]{target="_blank"}

In order to publish your project, you need to create a Cloudflare D1 database and connect it to your project.

[Learn how to create a D1 database](https://developers.cloudflare.com/d1/get-started/#2-create-a-database)
- [Create a D1 database][d1]
- Link it to your Cloudflare Pages project using the `DB` binding name

## Database

Unfortunately SQLite database is not supported in cloudflare environment and you should use another database.
You can simply create a D1 database in cloudflare and use Content Module's D1 adapter.

- Use [Nuxt Hub](/docs/deploy/nuxthub) to create, connect and manage D1 database for you.
- Or 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]
Redeploy your project.

::tip
Checkout the [**NuxtHub Integration**](/docs/deploy/nuxthub) to deploy your Nuxt Content project on your Cloudflare account with zero configuration and maximum performance.
::

[1]: https://developers.cloudflare.com/pages/get-started/#connect-your-git-provider-to-pages
[d1]: https://developers.cloudflare.com/d1/get-started/
37 changes: 1 addition & 36 deletions docs/content/docs/5.deploy/2.nuxthub.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,4 @@ navigation:
icon: i-simple-icons-nuxtdotjs
---

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.

You can do that in two ways:

- By defining the `NITRO_PRESET`{lang="ts-type"} to `cloudflare_pages`{lang="ts-type"} when running the build process, like so:

```bash
NITRO_PRESET=cloudflare_pages npm run build
```

Or by updating your Nuxt configuration:

```bash
"preset": "cloudflare_pages",
```

If you use the [Cloudflare Pages GitHub/GitLab integration][1]{target="_blank"} Nuxt does not require configuration for presets.

## Database

Unfortunately sqlite database is not supported in cloudflare environment and you should use another database.
You can simply create a D1 database in cloudflare and use Content Module's D1 adapter.

- You can simply use [Nuxt Hub][nuxt-hub] to create, connect and manage D1 database for you.
- 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]








[1]: https://developers.cloudflare.com/pages/get-started/#connect-your-git-provider-to-pages
[nuxt-hub]: https://hub.nuxt.com/docs/features/database
[d1]: https://developers.cloudflare.com/d1/get-started/
TODO
13 changes: 12 additions & 1 deletion docs/content/docs/5.deploy/2.vercel.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,19 @@ You can simply create a [Vercel Postgres][3] database and use Content Module's P

Checkout [official documentation][4] to create a Vercel Postgress database and connect it to your Vercel project. Nuxt Content will automatically detect connection url from environment variables in production.

```ts [nuxt.config.ts]
export default defineNuxtConfig({
content: {
database: {
type: 'postgres',
url: process.env.POSTGRES_URL,
/* Other options for `pg` */
}
}
})
```

[1]: https://vercel.com/docs/deployments/git
[2]: https://vercel.com/docs/cli
[3]: https://vercel.com/storage/postgres
[4]: https://vercel.com/docs/storage/vercel-postgres/quickstart#quickstart
[4]: https://vercel.com/docs/storage/vercel-postgres/quickstart#quickstart

0 comments on commit 1dac4d5

Please sign in to comment.