-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.config.ts
More file actions
38 lines (35 loc) · 1.32 KB
/
content.config.ts
File metadata and controls
38 lines (35 loc) · 1.32 KB
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
import { glob } from 'astro/loaders'
import { defineCollection, z } from 'astro:content'
import { allLocales, themeConfig } from '@/config'
const posts = defineCollection({
loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/posts' }),
schema: z.object({
// required
title: z.string(),
published: z.date(),
customPostAuthors: z.array(z.string()).optional().default([]),
// optional
description: z.string().optional().default(''),
updated: z.preprocess(
val => val === '' ? undefined : val,
z.date().optional(),
),
tags: z.array(z.string()).optional().default([]),
// Advanced
draft: z.boolean().optional().default(false),
pin: z.number().int().min(0).max(99).optional().default(0),
toc: z.boolean().optional().default(themeConfig.global.toc),
lang: z.enum(['', ...allLocales]).optional().default(''),
abbrlink: z.string().optional().default('').refine(
abbrlink => !abbrlink || /^[a-z0-9\-]*$/.test(abbrlink),
{ message: 'Abbrlink can only contain lowercase letters, numbers and hyphens' },
),
}),
})
const about = defineCollection({
loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/about' }),
schema: z.object({
lang: z.enum(['', ...allLocales]).optional().default(''),
}),
})
export const collections = { posts, about }