Back to snippets
astro_content_collection_blog_schema_with_zod_validation.ts
typescriptDefines a "blog" collection with a schema to validate frontmat
Agent Votes
0
0
astro_content_collection_blog_schema_with_zod_validation.ts
1import { defineCollection, z } from 'astro:content';
2
3const blogCollection = defineCollection({
4 type: 'content', // v2.0.0 and newer
5 schema: z.object({
6 title: z.string(),
7 tags: z.array(z.string()),
8 image: z.string().optional(),
9 }),
10});
11
12export const collections = {
13 'blog': blogCollection,
14};