Collection Types
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.
For both types, built-in fields are generated. Every collection includes these default fields:
id
: Unique content identifierstem
: File path without extension (used for sorting and location)extension
: File extensionmeta
: Custom fields not defined in the collection schema
Page type
defineCollection({
source: '**/*.md',
type: 'page'
})
Path generation
Nuxt Content will automatically generate a path for each file in the collection, making it easy to create URL mappings.
Here are examples of generated paths based on file structure:
File | Path |
---|---|
content/index.md | / |
content/about.md | /about |
content/blog/index.md | /blog |
content/blog/hello.md | /blog/hello |
content/1.guide/2.installation | /guide/installation |
queryCollection('COLLECTION').path('PATH')
to retrieve content by a specific path.Schema Overrides
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:
path
: Generated route pathtitle
: Page titledescription
: Page descriptionseo
: SEO metadata (to be used with Nuxt'suseSeoMeta
composable)body
: Page content parsed as ASTnavigation
: Page navigation configuration (for queryCollectionNavigation)
Here is the corresponding schema applied:
path: z.string(),
title: z.string(),
description: z.string(),
seo: z.intersection(
z.object({
title: z.string().optional(),
description: z.string().optional(),
meta: z.array(z.record(z.string(), z.any())).optional(),
link: z.array(z.record(z.string(), z.any())).optional(),
}),
z.record(z.string(), z.any()),
).optional().default({}),
body: z.object({
type: z.string(),
children: z.any(),
toc: z.any(),
}),
navigation: z.union([
z.boolean(),
z.object({
title: z.string(),
description: z.string(),
icon: z.string(),
}),
]).default(true),
Data type
defineCollection({
source: 'authors/**.yml',
type: 'data'
})
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.
With data collections, you have complete control over the schema, allowing you to define custom structures.
Ordering Files
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.
content/
1.frameworks/
1.vue.md
2.nuxt.md
2.examples/
1.vercel.md
2.netlify.md
3.heroku.md
index.md
.
character. Using any other separator will not work.