diff options
Diffstat (limited to 'examples/blog/src/content/config.ts')
-rw-r--r-- | examples/blog/src/content/config.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/examples/blog/src/content/config.ts b/examples/blog/src/content/config.ts new file mode 100644 index 000000000..b4e86c9f7 --- /dev/null +++ b/examples/blog/src/content/config.ts @@ -0,0 +1,21 @@ +import { defineCollection, z } from 'astro:content'; + +const blog = defineCollection({ + // Type-check frontmatter using a schema + schema: z.object({ + 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)), + heroImage: z.string().optional(), + }), +}); + +export const collections = { blog }; |