Skip to content

Commit

Permalink
feat: add image validation to schema
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishqmanuja authored and satnaing committed Sep 25, 2023
1 parent 817e67a commit e9d4303
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@ import { defineCollection, z } from "astro:content";

const blog = defineCollection({
type: "content",
schema: 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(),
canonicalURL: z.string().optional(),
}),
schema: ({ image }) =>
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: image()
.refine(img => img.width >= 1200 && img.height >= 630, {
message: "OpenGraph image must be at least 1200 X 630 pixels!",
})
.optional(),
description: z.string(),
canonicalURL: z.string().optional(),
}),
});

export const collections = { blog };

0 comments on commit e9d4303

Please sign in to comment.