main
 1import { defineCollection } from "astro:content";
 2import { glob } from "astro/loaders";
 3import { z } from "astro/zod";
 4import { DateTime } from "luxon";
 5import { SITE_CONFIG } from "./config";
 6
 7const typCollection = defineCollection({
 8  loader: glob({
 9    pattern: "**/[^_]*.{typ,typst}",
10    base: "./src/contents/posts",
11  }),
12  schema: z.object({
13    title: z.string(),
14    author: z.string().optional(),
15    desc: z.any().optional(),
16    date: z.string().transform((str) => {
17      const match = str.match(
18        /datetime\(\s*year:\s*(\d+),?\s*month:\s*(\d+),?\s*day:\s*(\d+)(?:,?\s*hour:\s*(\d+))?(?:,?\s*minute:\s*(\d+))?(?:,?\s*second:\s*(\d+))?,?\s*\)/,
19      );
20      if (match) {
21        const year = parseInt(match[1], 10);
22        const month = parseInt(match[2], 10);
23        const day = parseInt(match[3], 10);
24        const hour = match[4] ? parseInt(match[4], 10) : 0;
25        const minute = match[5] ? parseInt(match[5], 10) : 0;
26        const second = match[6] ? parseInt(match[6], 10) : 0;
27
28        const dt = DateTime.fromObject(
29          {
30            year,
31            month,
32            day,
33            hour,
34            minute,
35            second,
36          },
37          {
38            zone: SITE_CONFIG.timeZone,
39          },
40        );
41        return dt.toJSDate();
42      }
43      return z.NEVER;
44    }),
45  }),
46});
47
48export const collections = {
49  posts: typCollection,
50};