Astro2.0のfrontmatterとz.optional()

Astro2.0のfrontmatterとz.optional()

Markdown ファイルについて

最初エラーがでるのでMarkdownのfrontmatter要素はすべて書く必要があるのかと勘違いしたが
Markdownで使わないfrontmatter要素は src/content/config.ts の z.object の optional 関数を指 定することで使わなくても問題なくなった

ここで知った

実は公式ブログでも書いてた

---// `astro:content`から z defineCollection を読み込むimport { defineCollection, z } from "astro:content";// コレクションの定義const blogCollection = defineCollection({  schema: z.object({    layout: z.string(),    title: z.string(),    date: z.string().transform(str => new Date(str)),    description: z.string().optional(),    tags: z.array(z.string()).optional(),    featured: z.string().optional(),    heroImage: z.string().optional(),    author: z.string().optional(),    isDraft: z.boolean().optional(),    updatedDate: z      .string()      .transform(str => new Date(str))      .optional(),  }),});// 以下でコレクションを割り当てる コレクションを読み込む場合は// getcollection(以下の文字列) で可能export const collections = {  blog: blogCollection,  note: blogCollection,};---