abo的博客小站
POST/约 2 分钟

Hello Astro:用 7.1 起个极简博客

欢迎来到这个用 Astro 7.1 搭建的极简博客。本篇既是示例文章,也是 Astro 7 新特性的快速概览。

为什么是 Astro

Astro 是为内容驱动网站而生的框架——博客、文档、营销页都是它的主场。默认 零 JavaScript 发往浏览器,首屏起飞;同时保留 MPA(多页应用)结构,SEO 天然友好。

"The fastest build is the one that doesn't happen at all." —— Astro 7 发布博客

Astro 7 带来了什么

1. Rust 编译器

.astro 文件编译器从 Go 改写成 Rust。结合 Vite 8 + Rolldown,构建时间下降 15-61%。

2. View Transitions 内建

切页不再白屏闪一下。本博客全站用 <ClientRouter /> 启用浏览器原生 View Transitions API,点击文章卡片试试看。

3. AI 编码 Agent 友好

astro dev 能检测编码 Agent,可以后台运行 + 输出结构化 JSON 日志。写代码的时候体感很丝滑。

代码示例

import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';

const posts = defineCollection({
  loader: glob({ pattern: '**/*.md', base: './src/content/posts' }),
  schema: z.object({
    title: z.string(),
    description: z.string(),
    pubDate: z.coerce.date(),
  }),
});

接下来

happy hacking 🚀