From 4e7d9843d73ed08ef27d095ca9feae36465c6cb5 Mon Sep 17 00:00:00 2001 From: satnaing Date: Thu, 26 Jan 2023 22:39:26 +0630 Subject: [PATCH] refactor: define blog schema and clean up config --- src/content/config.ts | 15 +++------------ src/content/schemas.ts | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 src/content/schemas.ts diff --git a/src/content/config.ts b/src/content/config.ts index 3ad0d8e..d685fcd 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -1,17 +1,8 @@ -import { z, defineCollection } from "astro:content"; +import { defineCollection } from "astro:content"; +import { blogSchema } from "./schemas"; const blogCollection = defineCollection({ - schema: z.object({ - author: z.string(), - datetime: z.string(), // z.string().datetime() only available in Zod v3.20.2 - title: z.string(), - slug: z.string().optional(), - featured: z.boolean(), - draft: z.boolean(), - tags: z.array(z.string()), - ogImage: z.string().optional(), - description: z.string(), - }), + schema: blogSchema, }); export const collections = { diff --git a/src/content/schemas.ts b/src/content/schemas.ts new file mode 100644 index 0000000..9ea6915 --- /dev/null +++ b/src/content/schemas.ts @@ -0,0 +1,20 @@ +import { z } from "astro:content"; + +export const blogSchema = z.object({ + author: z.string(), + publishDatetime: z.string(), // z.string().datetime() only available in Zod v3.20.2 + title: z.string(), + slug: z.string().optional(), + featured: z.boolean(), + draft: z.boolean(), + tags: z.array(z.string()), + ogImage: z + .object({ + src: z.string(), + alt: z.string().optional(), + }) + .optional(), + description: z.string(), +}); + +export type BlogFrontmatter = z.infer;