eratic / sites / home / src / content.config.ts
300 words
 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';

/**
 * eratic.ro reads the other three sites straight off disk.
 *
 * No API, no build-order dependency, no duplicated copy: the home page globs
 * the same Markdown files blog, fav and io build from, so it cannot show
 * something that is not published or miss something that is.
 *
 * The schemas here are deliberately a subset — title, summary, date and the
 * one or two fields needed for a label. Zod strips anything it does not
 * declare, which is what makes this safe: `cover` and `photos` reference image
 * files by paths relative to *their* site, and trying to resolve those from
 * this project would be a build error. Not declaring them means they are
 * dropped before anything can try.
 */

/** Common to every entry on every site. */
const shared = z.object({
	title: z.string().optional(),
	summary: z.string(),
	pubDate: z.coerce.date(),
	draft: z.boolean().default(false),
});

const posts = defineCollection({
	loader: glob({ pattern: '**/[^_]*.{md,mdx}', base: '../blog/src/content/posts' }),
	schema: shared.extend({ title: z.string() }),
});

const photos = defineCollection({
	loader: glob({ pattern: '**/[^_]*.{md,mdx}', base: '../blog/src/content/photos' }),
	schema: shared.extend({
		title: z.string(),
		place: z.string().optional(),
		// Counted for the label, so it has to survive the strip. Only the length
		// is ever read — an open record keeps each entry without validating the
		// image paths, which this project cannot resolve.
		photos: z.array(z.record(z.string(), z.unknown())).optional(),
	}),
});

const favs = defineCollection({
	loader: glob({ pattern: '**/[^_]*.{md,mdx}', base: '../fav/src/content/favs' }),
	schema: shared.extend({
		title: z.string(),
		kind: z.enum(['object', 'book', 'film', 'music', 'other']),
		creator: z.string().optional(),
	}),
});

const issues = defineCollection({
	loader: glob({ pattern: '**/[^_]*.{md,mdx}', base: '../io/src/content/issues' }),
	schema: shared.extend({
		issue: z.number().int().positive(),
		links: z.array(z.record(z.string(), z.unknown())).optional(),
	}),
});

export const collections = { posts, photos, favs, issues };

static mirror of HEAD · about · clone: git clone https://git.makefuture.ro/eratic.git