Skip to content

Commit

Permalink
fix: make schema(s) strict (#23)
Browse files Browse the repository at this point in the history
If schema(s) are made with strict, it will disallow extra keys in the markdown frontmatter.
  • Loading branch information
shamwela authored Feb 1, 2023
1 parent 920046f commit dc026b3
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/content/_schemas.ts
Original file line number Diff line number Diff line change
@@ -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<typeof blogSchema>;

0 comments on commit dc026b3

Please sign in to comment.