this repo has no description
1import { defineCollection, z } from "astro:content";
2import { file, glob } from "astro/loaders";
3
4const blog = defineCollection({
5 loader: glob({ pattern: "**/*.md", base: "./src/content/posts" }),
6 schema: z.object({
7 title: z.string(),
8 date: z.date(),
9 colour: z.string(),
10 // no alt (empty as decorative)
11 image: z
12 .string()
13 .refine(
14 (value) => value.endsWith(".png"),
15 (val) => ({
16 message: `${val} must end with .png`,
17 }),
18 )
19 .optional(),
20 hasMdx: z.boolean().default(false),
21 }),
22});
23
24const blogMdx = defineCollection({
25 loader: glob({ pattern: "**/*.mdx", base: "./src/content/posts" }),
26 schema: z.object({
27 title: z.string(),
28 }),
29});
30
31export type nav = {
32 name: string;
33 url: string | false;
34 children?: nav[];
35};
36
37const navSchema: z.ZodType<nav> = z.lazy(() =>
38 z.object({
39 name: z.string(),
40 url: z.string().or(z.literal(false)),
41 children: z.optional(z.array(navSchema)),
42 }),
43);
44
45const nav = defineCollection({
46 loader: file("src/content/navList.json"),
47 schema: z.array(navSchema),
48});
49
50export const collections = { blog, blogMdx, nav };