summaryrefslogtreecommitdiff
path: root/src/content.config.ts
diff options
context:
space:
mode:
authorDawid Rycerz <dawid@rycerz.xyz>2025-07-03 10:56:21 +0300
committerDawid Rycerz <dawid@rycerz.xyz>2025-07-03 10:56:21 +0300
commit456cf011b36de91c9936994b1fa45703adcd309b (patch)
tree8e60daf998f731ac50d100fa490eaecae1168042 /src/content.config.ts
Initial fork of chrismwilliams/astro-theme-cactus theme
Diffstat (limited to 'src/content.config.ts')
-rw-r--r--src/content.config.ts58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/content.config.ts b/src/content.config.ts
new file mode 100644
index 0000000..271b472
--- /dev/null
+++ b/src/content.config.ts
@@ -0,0 +1,58 @@
+import { defineCollection, z } from "astro:content";
+import { glob } from "astro/loaders";
+
+function removeDupsAndLowerCase(array: string[]) {
+ return [...new Set(array.map((str) => str.toLowerCase()))];
+}
+
+const titleSchema = z.string().max(60);
+
+const baseSchema = z.object({
+ title: titleSchema,
+});
+
+const post = defineCollection({
+ loader: glob({ base: "./src/content/post", pattern: "**/*.{md,mdx}" }),
+ schema: ({ image }) =>
+ baseSchema.extend({
+ description: z.string(),
+ coverImage: z
+ .object({
+ alt: z.string(),
+ src: image(),
+ })
+ .optional(),
+ draft: z.boolean().default(false),
+ ogImage: z.string().optional(),
+ tags: z.array(z.string()).default([]).transform(removeDupsAndLowerCase),
+ publishDate: z
+ .string()
+ .or(z.date())
+ .transform((val) => new Date(val)),
+ updatedDate: z
+ .string()
+ .optional()
+ .transform((str) => (str ? new Date(str) : undefined)),
+ }),
+});
+
+const note = defineCollection({
+ loader: glob({ base: "./src/content/note", pattern: "**/*.{md,mdx}" }),
+ schema: baseSchema.extend({
+ description: z.string().optional(),
+ publishDate: z
+ .string()
+ .datetime({ offset: true }) // Ensures ISO 8601 format with offsets allowed (e.g. "2024-01-01T00:00:00Z" and "2024-01-01T00:00:00+02:00")
+ .transform((val) => new Date(val)),
+ }),
+});
+
+const tag = defineCollection({
+ loader: glob({ base: "./src/content/tag", pattern: "**/*.{md,mdx}" }),
+ schema: z.object({
+ title: titleSchema.optional(),
+ description: z.string().optional(),
+ }),
+});
+
+export const collections = { post, note, tag };