summaryrefslogtreecommitdiff
path: root/src/content/config.ts
blob: 1fca4a0646d18897ef2c312fe280a33eeda3a22a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { defineCollection, z } from 'astro:content';

const namesCollection = defineCollection({
  type: 'data',
  schema: z.object({
    domain: z.string(),
    name: z.string(),
    title: z.string().max(80).optional(),
    url: z.string().url().optional(),
    email: z.string().email().optional(),
    github: z.string().optional(),
    candidate: z.boolean().optional(),
    invalid: z.boolean().optional(),
  }).refine(
    (data) => {
      // If not a candidate, title is required
      if (!data.candidate) {
        return !!data.title;
      }
      return true;
    },
    {
      message: "Title is required for non-candidates",
      path: ["title"],
    }
  ),
});

// Export the collections
export const collections = {
  'names': namesCollection,
};