chore: use z.coerce.date() to pass input through new Date(input). (#8383)

This commit is contained in:
Michael Oliver 2023-09-04 11:46:24 +01:00 committed by GitHub
parent 535a458999
commit 77922ae5db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 18 deletions

View file

@ -6,14 +6,8 @@ const blog = defineCollection({
title: z.string(),
description: z.string(),
// Transform string to Date object
pubDate: z
.string()
.or(z.date())
.transform((val) => new Date(val)),
updatedDate: z
.string()
.optional()
.transform((str) => (str ? new Date(str) : undefined)),
pubDate: z.coerce.date(),
updatedDate: z.coerce.date().optional(),
heroImage: z.string().optional(),
}),
});

View file

@ -4,11 +4,8 @@ const blog = defineCollection({
schema: z.object({
title: z.string(),
description: z.string(),
pubDate: z.string().transform((str) => new Date(str)),
updatedDate: z
.string()
.optional()
.transform((str) => (str ? new Date(str) : undefined)),
pubDate: z.coerce.date(),
updatedDate: z.coerce.date().optional(),
heroImage: z.string().optional(),
}),
});

View file

@ -4,11 +4,8 @@ const blog = defineCollection({
schema: z.object({
title: z.string(),
description: z.string(),
pubDate: z.string().transform((str) => new Date(str)),
updatedDate: z
.string()
.optional()
.transform((str) => (str ? new Date(str) : undefined)),
pubDate: z.coerce.date(),
updatedDate: z.coerce.date().optional(),
heroImage: z.string().optional(),
}),
});