blog/src/content.config.ts
radishzzz 2f80ab9523 feat: add new post creation script and theme update script, remove git-protect.list and sync-upstream.sh
- Deleted `README-zh.md` and `README.md` as they are no longer needed.
- Removed `git-protect.list` to streamline the synchronization process.
- Introduced `new-post.ts` script for easier blog post creation with default metadata.
- Added `update-theme.ts` script to simplify theme updates from the upstream repository.
- Updated content configuration to handle optional updated dates correctly.
- Adjusted pin values in theme guide documents to allow a range from 0-99 instead of 1-99.
2025-05-28 20:41:08 +01:00

37 lines
1.3 KiB
TypeScript

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(),
// 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 }