Complete the code to define a new collection named 'blog'.
import { defineCollection } from 'astro:content'; const blog = defineCollection({ schema: [1] });
The schema must be an object schema defining the structure of the collection entries. Using z.object({ title: z.string() }) correctly defines a schema with a title string.
Complete the code to import the 'z' library for schema definitions.
import { [1] } from 'astro:content';
You need to import z from 'astro:content' to define schemas for collections.
Fix the error in the schema definition to require a 'date' field of type string.
const event = defineCollection({
schema: z.object({
title: z.string(),
date: [1]
})
});The 'date' field should be a string to represent dates in ISO format or similar. Using z.string() correctly enforces this.
Fill both blanks to define a collection with a schema that requires a 'title' string and an optional 'tags' array of strings.
const articles = defineCollection({
schema: z.object({
title: [1],
tags: [2]
})
});The 'title' must be a string, so z.string() is correct. The 'tags' field is an optional array of strings, so z.array(z.string()).optional() correctly defines that.
Fill all three blanks to create a collection schema with 'title' as string, 'published' as boolean, and 'views' as optional number.
const posts = defineCollection({
schema: z.object({
title: [1],
published: [2],
views: [3]
})
});The 'title' is a string, so z.string() is correct. 'published' is a boolean, so z.boolean() fits. 'views' is an optional number, so z.number().optional() is the right choice.
