feat: new blog layout and props

This commit is contained in:
KazooTTT
2025-02-05 15:27:29 +08:00
parent ea645368e9
commit fea129eb98
12 changed files with 36 additions and 50 deletions

View File

@ -6,43 +6,30 @@ function removeDupsAndLowerCase(array: string[]) {
}
const baseSchema = z.object({
title: z.string().max(60),
title: z.string()
});
const post = defineCollection({
loader: glob({ base: "./src/content/post", pattern: "**/*.{md,mdx}" }),
schema: ({ image }) =>
schema: () =>
baseSchema.extend({
description: z.string(),
coverImage: z
.object({
alt: z.string(),
src: image(),
})
.optional(),
description: z.string().optional().nullable(),
draft: z.boolean().default(false),
ogImage: z.string().optional(),
banner: z.string().optional(),
tags: z.array(z.string()).default([]).transform(removeDupsAndLowerCase),
publishDate: z
.string()
.or(z.date())
.transform((val) => new Date(val)),
updatedDate: z
.string()
.optional()
.transform((str) => (str ? new Date(str) : undefined)),
categories: z.array(z.string()).default([]).transform(removeDupsAndLowerCase),
date: z.union([z.string(), z.date()]).transform((val) => new Date(val)),
date_modified: z.date().optional(),
}),
});
const note = defineCollection({
loader: glob({ base: "./src/content/note", pattern: "**/*.{md,mdx}" }),
schema: baseSchema.extend({
description: z.string().optional(),
publishDate: z
.string()
.datetime({ offset: true }) // Ensures ISO 8601 format with offsets allowed (e.g. "2024-01-01T00:00:00Z" and "2024-01-01T00:00:00+02:00")
.transform((val) => new Date(val)),
description: z.string().optional().nullable(),
date: z.union([z.string(), z.date()]).transform((val) => new Date(val)),
}),
});
export const collections = { post, note };