前端

用 Astro 搭建一个极速的个人博客

2026/05/28 约 2 分钟
用 Astro 搭建一个极速的个人博客

我一直想要一个加载够快、写作够爽、维护够省心的博客。试过 WordPress、Hexo、Next.js 之后,最终落在了 Astro 上。

为什么是 Astro

Astro 最打动我的是它的 孤岛架构(Islands Architecture)

  • 页面默认输出纯 HTML/CSS,零 JavaScript
  • 只有真正需要交互的组件才会「激活」,按需加载;
  • 内容用 Markdown 管理,天然适合博客。

一个博客 90% 的内容是静态文字,凭什么要给用户塞一大堆 JS?

内容集合

Astro 的 Content Collections 提供了类型安全的 frontmatter 校验:

const blog = defineCollection({
  loader: glob({ pattern: '**/*.md', base: './src/content/blog' }),
  schema: z.object({
    title: z.string(),
    pubDate: z.coerce.date(),
    tags: z.array(z.string()).default([]),
  }),
});

写错字段名,构建时直接报错,再也不怕 typo。

渲染文章

const { Content, headings } = await render(post);

headings 还能直接拿来生成目录(TOC),非常方便。

小结

如果你也想要一个干净、快速、好维护的博客,Astro 值得一试。下一篇我会聊聊样式方案。

💬 评论区占位 —— 可在此接入 GiscusWaline