blog/src/content/config.ts

35 lines
824 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
2023-08-31 15:33:14 +00:00
schema: ({ image }) =>
z.object({
title: z.string(),
date: z.date(),
2023-08-31 03:47:22 +00:00
2023-08-31 15:33:14 +00:00
// 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(),
2023-08-31 03:47:22 +00:00
2023-08-31 15:33:14 +00:00
heroImage: image().optional(),
heroAlt: z.string().optional(),
tags: z.array(z.string()),
draft: z.boolean().default(false),
2023-09-01 14:24:12 +00:00
math: z.boolean().default(false),
2023-09-01 17:38:59 +00:00
toc: z.boolean().default(false),
2023-08-31 15:33:14 +00:00
}),
2023-08-31 00:30:45 +00:00
});
2023-08-31 03:47:22 +00:00
export const collections = { posts };