跳到主要内容

VoidLab

记录学习、生活与思考的个人网站

用 Astro Content Layer 组织内容

· 约 1 分钟

#astro#content

为什么需要内容层

Astro 7 的 Content Layer API 用 glob loader 加载 Markdown 集合,配合 zod schema 做前置数据校验。这篇正文用于验证首页摘要回退:当 frontmatter 缺少 description 时,从正文提取前若干字作为摘要。

核心概念

  • astro/loaders 的 glob loader 按模式加载内容文件
  • src/content.config.ts 用 zod 定义 schema
  • getCollection('blog', filterFn) 在构建期取数据

小结

内容优先的关键是把正文与展示解耦。占位内容,待替换为真实文章。

活动日历

2026年8月

点击日期查看当天内容

天气

选好后天气按该地点显示;不选则按访问者 IP 自动定位。

上海
--°C晴

天气加载中