src/content/config.ts 630 B raw
1
import { z, defineCollection } from "astro:content";
2
3
function removeDupsAndLowerCase(array: string[]) {
4
	if (!array.length) return array;
5
	const lowercaseItems = array.map((str) => str.toLowerCase());
6
	const distinctItems = new Set(lowercaseItems);
7
	return Array.from(distinctItems);
8
}
9
10
const post = defineCollection({
11
	schema: z.object({
12
		title: z.string().max(60),
13
		description: z.string().min(50).max(160),
14
		publishDate: z.string().transform((str) => new Date(str)),
15
		tags: z.array(z.string()).default([]).transform(removeDupsAndLowerCase),
16
		ogImage: z.string().optional(),
17
	}),
18
});
19
20
export const collections = { post };