Commit a1d7f6e

HPCesia <me@hpcesia.com>
2026-02-04 10:37:02
Fix value and type of date in posts' metadata
They are `"datetime(year: xxxx, month: xx, day: xx)"` before.
1 parent d3fcee2
Changed files (1)
src/content.config.ts
@@ -11,7 +11,19 @@ const typCollection = defineCollection({
     title: z.string(),
     author: z.string().optional(),
     desc: z.any().optional(),
-    date: z.any(),
+    date: z.string().transform((str) => {
+      const match = str.match(
+        /datetime\(year:\s*(\d+),\s*month:\s*(\d+),\s*day:\s*(\d+)\)/,
+      );
+      if (match) {
+        return new Date(
+          parseInt(match[1], 10),
+          parseInt(match[2], 10) - 1,
+          parseInt(match[3], 10),
+        );
+      }
+      return z.NEVER;
+    }),
   }),
 });