29 lines
618 B
TypeScript
29 lines
618 B
TypeScript
import { defineCollection, z } from "astro:content";
|
|
|
|
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),
|
|
}),
|
|
});
|
|
|
|
export const collections = { posts };
|