用 Astro Content Layer 组织内容
· 约 1 分钟
为什么需要内容层
Astro 7 的 Content Layer API 用 glob loader 加载 Markdown 集合,配合 zod schema 做前置数据校验。这篇正文用于验证首页摘要回退:当 frontmatter 缺少 description 时,从正文提取前若干字作为摘要。
核心概念
astro/loaders的globloader 按模式加载内容文件src/content.config.ts用zod定义 schemagetCollection('blog', filterFn)在构建期取数据
小结
内容优先的关键是把正文与展示解耦。占位内容,待替换为真实文章。
