Collections

Collection Types

Learn about the two types of collections you can define in Nuxt Content.

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 identifier
  • stem: File path without extension (used for sorting and location)
  • extension: File extension
  • meta: Custom fields not defined in the collection schema

Page type

defineCollection({
  source: '**/*.md',
  type: 'page'
})
Use the page type if there is a 1-to-1 relationship between content files and pages on your site.

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:

FilePath
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
You can use the helper 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 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)

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),
You can override any of these fields by defining them in the collection’s schema.

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.

There’s no strict relationship between collection type and file extension. For instance, a page collection can use Markdown or YAML or JSON files, and data collections can use any of these formats as well.

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.

Directory structure
content/
  1.frameworks/
    1.vue.md
    2.nuxt.md
  2.examples/
    1.vercel.md
    2.netlify.md
    3.heroku.md
    index.md
Separate number from file name using . character. Using any other separator will not work.