Files

YAML

How to define, write and query YAML data.

Define Collection

content.config.ts
export const collections = {
  authors: defineCollection({
    type: 'data',
    source: 'authors/**.yml',
    schema: z.object({
      name: z.string(),
      avatar: z.string(),
      url: z.string()
    })
  })
}

Create .yml files

Create authors files in content/authors/ directory.

name: Ahad Birang
avatar: https://avatars.githubusercontent.com/u/2047945?v=4
url: https://github.com/farnabaz

Query Data

Now we can query authors:

// Find a single author
const theAuthor = await queryCollection('authors')
  .where('stem', '=', 'larbish')
  .first()

// Get all authors
const authors = await queryCollection('authors')
  .order('name', 'DESC')
  .all()