summaryrefslogtreecommitdiff
path: root/src/content.config.ts
blob: 27c16d648a3e68336ca4c1c7a1b29cd9343a8905 (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
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { defineCollection, z } from "astro:content";
import { glob } from "astro/loaders";
import { pleromaLoader } from "./loaders/pleroma";

function removeDupsAndLowerCase(array: string[]) {
	return [...new Set(array.map((str) => str.toLowerCase()))];
}

const titleSchema = z.string().max(60);

const baseSchema = z.object({
	title: titleSchema,
});

const post = defineCollection({
	loader: glob({ base: "./src/content/post", pattern: "**/*.{md,mdx}" }),
	schema: ({ image }) =>
		baseSchema.extend({
			description: z.string(),
			coverImage: z
				.object({
					alt: z.string(),
					src: image(),
				})
				.optional(),
			draft: z.boolean().default(false),
			ogImage: z.string().optional(),
			tags: z.array(z.string()).default([]).transform(removeDupsAndLowerCase),
			publishDate: z
				.string()
				.or(z.date())
				.transform((val) => new Date(val)),
			updatedDate: z
				.string()
				.optional()
				.transform((str) => (str ? new Date(str) : undefined)),
			language: z.string().optional(),
			sourceUrl: z.string().optional(),
			author: z.string().optional(),
		}),
});

const pleroma = defineCollection({
	loader: pleromaLoader({
		instanceUrl: "https://social.craftknight.com",
		username: "dawid",
		maxPosts: -1, // Fetch all posts
		allowedTags: [
			"#miniblog",
			"#vanlife",
			"#microblog",
			"#giereczkowo",
			"#finlandia",
			"#nordkapp",
			"#norwegia",
			"#szwecja",
			"#starlink",
			"#flipperzero",
			"#meshcore",
			"#belgia",
			"#francja",
			"#hiszpania",
			"#madryt",
			"#gibraltar",
			"#termowizja",
			"#wlochy",
			"#włochy",
			"#sycylia",
		],
	}),
	schema: baseSchema.extend({
		description: z.string().optional(),
		publishDate: z.date().or(z.string().transform((val) => new Date(val))),
		sourceUrl: z.string().optional(),
		language: z.string().optional(),
		tags: z.array(z.string()).default([]).transform(removeDupsAndLowerCase),
		draft: z.boolean().default(false),
		author: z.string().optional(),
	}),
});

const tag = defineCollection({
	loader: glob({ base: "./src/content/tag", pattern: "**/*.{md,mdx}" }),
	schema: z.object({
		title: titleSchema.optional(),
		description: z.string().optional(),
	}),
});

export const collections = { post, tag, pleroma };