Use date-fns for parsing pubDate, use Date instead of string

This commit is contained in:
2023-11-26 07:52:39 -06:00
parent a205436bc4
commit 2184dcd202
4 changed files with 29 additions and 2 deletions

View File

@@ -1,11 +1,16 @@
import { z, defineCollection } from 'astro:content';
import { parse } from 'date-fns';
const blogCollection = defineCollection({
type: 'content', // v2.5.0 and later
schema: z.object({
title: z.string(),
description: z.string(),
pubDate: z.string(),
pubDate: z.string().transform((date) =>
z.date().parse(
parse(date, 'yyyy-MM-dd HH:mm:ss XXXX', new Date())
)
),
tags: z.array(z.string()),
preview_image: z.string().optional(),
}),