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 };