content-collections icon indicating copy to clipboard operation
content-collections copied to clipboard

schema is only validation? can we account for coercion too?

Open airtonix opened this issue 1 year ago • 1 comments

It'd be nice to be able to use zod coercion to turn yaml ISO date strings into JS Date objects.

z.string().pipe(z.coerce.date())

z.string().transform((value) => new Date(value))

but these end up creating typeerrors:

image

airtonix avatar Apr 18 '24 23:04 airtonix

You can use coerce or transform, but the output must be a valid JSON object since content collections store documents as JSON files. There is an existing issue addressing the problem with the date (#29).

sdorra avatar Apr 19 '24 07:04 sdorra