| 1 | import { z, defineCollection } from "astro:content"; |
| 2 | import { glob } from "astro/loaders"; |
| 3 | |
| 4 | function removeDupsAndLowerCase(array: string[]) { |
| 5 | if (!array.length) return array; |
| 6 | const lowercaseItems = array.map((str) => str.toLowerCase()); |
| 7 | const distinctItems = new Set(lowercaseItems); |
| 8 | return Array.from(distinctItems); |
| 9 | } |
| 10 | |
| 11 | const post = defineCollection({ |
| 12 | loader: glob({ pattern: "**/*.{md,mdx}", base: "./src/content/post" }), |
| 13 | schema: ({ image }) => |
| 14 | z.object({ |
| 15 | title: z.string(), |
| 16 | description: z.string().min(10).max(160), |
| 17 | publishDate: z.string().transform((str) => new Date(str)), |
| 18 | tags: z.array(z.string()).default([]).transform(removeDupsAndLowerCase), |
| 19 | ogImage: z.union([image(), z.string().url()]).optional(), |
| 20 | hidden: z.boolean().optional().default(false), |
| 21 | atUri: z.string().optional(), |
| 22 | }), |
| 23 | }); |
| 24 | |
| 25 | const pages = defineCollection({ |
| 26 | loader: glob({ pattern: "**/*.{md,mdx}", base: "./src/content/pages" }), |
| 27 | schema: z |
| 28 | .object({ |
| 29 | title: z.string().optional(), |
| 30 | }) |
| 31 | .optional(), |
| 32 | }); |
| 33 | |
| 34 | export const collections = { post, pages }; |