mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 07:33:07 +08:00
refactor: define blog schema and clean up config
This commit is contained in:
+3
-12
@@ -1,17 +1,8 @@
|
|||||||
import { z, defineCollection } from "astro:content";
|
import { defineCollection } from "astro:content";
|
||||||
|
import { blogSchema } from "./schemas";
|
||||||
|
|
||||||
const blogCollection = defineCollection({
|
const blogCollection = defineCollection({
|
||||||
schema: z.object({
|
schema: blogSchema,
|
||||||
author: z.string(),
|
|
||||||
datetime: z.string(), // z.string().datetime() only available in Zod v3.20.2
|
|
||||||
title: z.string(),
|
|
||||||
slug: z.string().optional(),
|
|
||||||
featured: z.boolean(),
|
|
||||||
draft: z.boolean(),
|
|
||||||
tags: z.array(z.string()),
|
|
||||||
ogImage: z.string().optional(),
|
|
||||||
description: z.string(),
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export const collections = {
|
export const collections = {
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { z } from "astro:content";
|
||||||
|
|
||||||
|
export const blogSchema = z.object({
|
||||||
|
author: z.string(),
|
||||||
|
publishDatetime: z.string(), // z.string().datetime() only available in Zod v3.20.2
|
||||||
|
title: z.string(),
|
||||||
|
slug: z.string().optional(),
|
||||||
|
featured: z.boolean(),
|
||||||
|
draft: z.boolean(),
|
||||||
|
tags: z.array(z.string()),
|
||||||
|
ogImage: z
|
||||||
|
.object({
|
||||||
|
src: z.string(),
|
||||||
|
alt: z.string().optional(),
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
|
description: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type BlogFrontmatter = z.infer<typeof blogSchema>;
|
||||||
Reference in New Issue
Block a user