summaryrefslogtreecommitdiff
path: root/apps/web/content-collections.ts
blob: b9904bf6dae8b5bb971f9c2fcdf8d064c627bfe3 (plain) (blame)
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
import { defineCollection, defineConfig } from "@content-collections/core";
import { z } from "zod";

const changelog = defineCollection({
	name: "changelog",
	directory: "content/changelog",
	include: "*.md",
	schema: z.object({
		content: z.string(),
		version: z.string(),
		date: z.string(),
		title: z.string(),
		description: z.string().optional(),
		changes: z.array(
			z.object({
				type: z.string(),
				text: z.string(),
			}),
		),
	}),
	transform: async (doc, { collection }) => {
		const allDocs = await collection.documents();
		const sorted = [...allDocs].sort((a, b) =>
			b.version.localeCompare(a.version, undefined, { numeric: true }),
		);
		const isLatest = sorted[0]?.version === doc.version;
		return { ...doc, isLatest };
	},
});

export default defineConfig({
	content: [changelog],
});