blog/src/content/config.ts

29 lines
618 B
TypeScript
Raw Normal View History

2023-08-31 03:47:22 +00:00
import { defineCollection, z } from "astro:content";
2023-08-31 00:30:45 +00:00
2023-08-31 03:47:22 +00:00
const posts = defineCollection({
type: "content",
// Type-check frontmatter using a schema
schema: z.object({
title: z.string(),
date: z.date(),
// Transform string to Date object
pubDate: z
.string()
.or(z.date())
.transform((val) => new Date(val))
.optional(),
updatedDate: z
.string()
.optional()
.transform((str) => (str ? new Date(str) : undefined))
.optional(),
tags: z.array(z.string()),
draft: z.boolean().default(false),
}),
2023-08-31 00:30:45 +00:00
});
2023-08-31 03:47:22 +00:00
export const collections = { posts };