mirror of
https://github.com/KazooTTT/kazoottt-blog-v2.git
synced 2025-06-22 10:11:29 +08:00
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { defineCollection, z } from "astro:content";
|
|
import { glob } from "astro/loaders";
|
|
|
|
function removeDupsAndLowerCase(array: string[]) {
|
|
return [...new Set(array.map((str) => str.toLowerCase()))];
|
|
}
|
|
|
|
const baseSchema = z.object({
|
|
title: z.string(),
|
|
});
|
|
|
|
const post = defineCollection({
|
|
loader: glob({ base: "./src/content/post", pattern: "**/*.{md,mdx}" }),
|
|
schema: () =>
|
|
baseSchema.extend({
|
|
description: z.string().optional().nullable(),
|
|
draft: z.boolean().default(false),
|
|
banner: z.string().optional(),
|
|
tags: z.array(z.string()).default([]).transform(removeDupsAndLowerCase),
|
|
date: z.union([z.string(), z.date()]).transform((val) => new Date(val)),
|
|
date_modified: z.date().optional(),
|
|
data_created: z.date().optional(),
|
|
category: z.string().optional().nullable(),
|
|
}),
|
|
});
|
|
|
|
const note = defineCollection({
|
|
loader: glob({ base: "./src/content/note", pattern: "**/*.{md,mdx}" }),
|
|
schema: baseSchema.extend({
|
|
description: z.string().optional().nullable(),
|
|
date: z.union([z.string(), z.date()]).transform((val) => new Date(val)),
|
|
date_modified: z.date().optional(),
|
|
data_created: z.date().optional(),
|
|
tags: z.array(z.string()).default([]).transform(removeDupsAndLowerCase),
|
|
}),
|
|
});
|
|
|
|
export const collections = { post, note };
|