import { defineCollection, z } from "astro:content";
import { glob } from "astro/loaders";
// =============================================================================
// src/content/config.ts — Zod-typed content collections (Astro 5 Content Layer).
// Every Markdown/MDX collection is validated against a Zod schema at build time,
// so `getCollection("blog")` returns fully-typed entries — never raw frontmatter.
// A frontmatter typo fails `astro check` instead of shipping a broken page.
// Astro 5 note: collections use the Content Layer `loader` API. `glob()` reads
// files from disk; `z` is re-exported from `astro:content` (do NOT import zod
// directly here — Astro's copy carries the image() helper and stays in sync).
// See the astro-architect skill for when content collections are the right tool
// vs. an Astro endpoint or a database.
// =============================================================================
const blog = defineCollection({
loader: glob({ pattern: "**/*.{md,mdx}", base: "./src/content/blog" }),
// Coerced to a Date so templates can format it with toLocaleDateString.
pubDate: z.coerce.date(),
updatedDate: z.coerce.date().optional(),
// Discriminate draft vs. published instead of a loose boolean where it helps.
draft: z.boolean().default(false),
tags: z.array(z.string()).default([]),
author: z.string().default("dmwd-io"),
// Register every collection here. The export name is the collection name used
// in getCollection("blog").
export const collections = { blog };