-
Notifications
You must be signed in to change notification settings - Fork 7
/
config.ts
107 lines (98 loc) · 2.79 KB
/
config.ts
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { imageMetadata } from '@/helpers/images';
import { urlJoin } from '@/helpers/tools';
import options from '@/options';
import { defineCollection, z } from 'astro:content';
export const defaultCover = '/images/default-cover.jpg';
// Copied and modified from https://github.com/zce/velite/blob/main/src/schemas/slug.ts
// The slug is internally supported by Astro with 'content' type.
// We add the slug here for validating the YAML configuration.
const slug = () =>
z
.string()
.min(3)
.max(200)
.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/i, 'Invalid slug');
const image = (fallbackImage: string) =>
z
.string()
.optional()
.default(fallbackImage)
.transform((file) => imageMetadata(file));
// Categories Collection
const categoriesCollection = defineCollection({
type: 'data',
schema: z.object({
name: z.string().max(20),
slug: slug(),
cover: image(defaultCover),
description: z.string().max(999).optional(),
}),
});
// Friends Collection
const friendsCollection = defineCollection({
type: 'data',
schema: z.array(
z
.object({
website: z.string().max(40),
description: z.string().optional(),
homepage: z.string().url(),
poster: z
.string()
.transform((poster) => (poster.startsWith('/') ? urlJoin(options.assetsPrefix(), poster) : poster)),
favicon: z.string().optional(),
})
.transform((data) => {
if (data.favicon === undefined) {
data.favicon = `${data.homepage}/favicon.ico`;
}
return data;
}),
),
});
// Posts Collection
const postsCollection = defineCollection({
type: 'content',
schema: z.object({
title: z.string().max(99),
date: z.date(),
updated: z.date().optional(),
comments: z.boolean().optional().default(true),
alias: z.array(z.string()).optional().default([]),
tags: z.array(z.string()).optional().default([]),
category: z.string(),
summary: z.string().optional().default(''),
cover: image(defaultCover),
published: z.boolean().optional().default(true),
}),
});
// Pages Collection
const pagesCollection = defineCollection({
type: 'content',
schema: z.object({
title: z.string().max(99),
date: z.date(),
updated: z.date().optional(),
comments: z.boolean().optional().default(true),
cover: image(defaultCover),
published: z.boolean().optional().default(true),
friend: z.boolean().optional().default(false),
}),
});
// Tags Collection
const tagsCollection = defineCollection({
type: 'data',
schema: z.array(
z.object({
name: z.string().max(20),
slug: slug(),
}),
),
});
export const collections = {
categories: categoriesCollection,
friends: friendsCollection,
pages: pagesCollection,
posts: postsCollection,
tags: tagsCollection,
};