From dc026b38defa760d77eddcddb1d4f12fdf8fff99 Mon Sep 17 00:00:00 2001 From: Sha Mwe La <62544170+shamwela@users.noreply.github.com> Date: Wed, 1 Feb 2023 12:13:41 +0630 Subject: [PATCH] fix: make schema(s) strict (#23) If schema(s) are made with strict, it will disallow extra keys in the markdown frontmatter. --- src/content/_schemas.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/content/_schemas.ts b/src/content/_schemas.ts index 7a4f6639e..66aa85b2d 100644 --- a/src/content/_schemas.ts +++ b/src/content/_schemas.ts @@ -1,15 +1,17 @@ import { z } from "astro:content"; -export const blogSchema = z.object({ - author: z.string().optional(), - pubDatetime: z.date(), - title: z.string(), - postSlug: z.string().optional(), - featured: z.boolean().optional(), - draft: z.boolean().optional(), - tags: z.array(z.string()).default(["others"]), - ogImage: z.string().optional(), - description: z.string(), -}); +export const blogSchema = z + .object({ + author: z.string().optional(), + pubDatetime: z.date(), + title: z.string(), + postSlug: z.string().optional(), + featured: z.boolean().optional(), + draft: z.boolean().optional(), + tags: z.array(z.string()).default(["others"]), + ogImage: z.string().optional(), + description: z.string(), + }) + .strict(); export type BlogFrontmatter = z.infer;