|
| 1 | +// 1. Import utilities from `astro:content` |
| 2 | +import { defineCollection } from "astro:content"; |
| 3 | + |
| 4 | +// 2. Import loader(s) |
| 5 | +import { glob, file } from "astro/loaders"; |
| 6 | + |
| 7 | +// 3. Import Zod |
| 8 | +import { z } from "astro/zod"; |
| 9 | + |
| 10 | +const articleSchema = z.object({ |
| 11 | + title: z.string(), |
| 12 | + author: z.string(), |
| 13 | + description: z.string().optional(), |
| 14 | + pubDate: z.coerce.date(), |
| 15 | + updatedDate: z.coerce.date().optional(), |
| 16 | + thumbnail: z.string().optional(), |
| 17 | +}); |
| 18 | + |
| 19 | +// 4. Define your collection(s) |
| 20 | +const about = defineCollection({ |
| 21 | + loader: glob({ pattern: "**/*.md", base: "./src/content/about" }), |
| 22 | + schema: articleSchema, |
| 23 | +}); |
| 24 | + |
| 25 | +const article = defineCollection({ |
| 26 | + loader: glob({ |
| 27 | + pattern: "**/*.{md,mdx}", |
| 28 | + base: "./src/content/article", |
| 29 | + }), |
| 30 | + schema: articleSchema, |
| 31 | +}); |
| 32 | + |
| 33 | +const illust = defineCollection({ |
| 34 | + loader: glob({ |
| 35 | + pattern: "**/*.md", |
| 36 | + base: "./src/content/illust", |
| 37 | + }), |
| 38 | + schema: z.object({ |
| 39 | + title: z.string(), |
| 40 | + date: z.coerce.date(), |
| 41 | + tags: z.array(z.string()).optional(), |
| 42 | + description: z.string().optional(), |
| 43 | + series: z.string().optional(), |
| 44 | + link: z.string().optional(), |
| 45 | + }), |
| 46 | +}); |
| 47 | + |
| 48 | +const onhourwritings = defineCollection({ |
| 49 | + loader: glob({ |
| 50 | + pattern: "**/*.md", |
| 51 | + }), |
| 52 | +}); |
| 53 | + |
| 54 | +const resources = defineCollection({}); |
| 55 | +const templates = defineCollection({}); |
| 56 | + |
| 57 | +// 5. Export a single `collections` object to register your collection(s) |
| 58 | +export const collections = { |
| 59 | + about, |
| 60 | + article, |
| 61 | + illust, |
| 62 | + onhourwritings, |
| 63 | + resources, |
| 64 | + templates, |
| 65 | +}; |
0 commit comments