Skip to content

Astro + Starlight 快速上手指南

  • 安装了 Node.js(v18+)
  • 有 GitHub 账号
  • 会基本的命令行操作
Terminal window
npm create astro@latest my-site
cd my-site
Terminal window
npx astro add starlight --yes

src/content/docs/ 下创建 .mdx 文件:

---
title: 我的页面
description: 页面描述
---
这里写你的内容...
Terminal window
npm run dev

打开 http://localhost:4321 查看效果。

推送到 GitHub,配置 GitHub Actions 自动部署。

Terminal window
git add -A
git commit -m "Initial commit"
git push

Starlight 自带暗色模式切换,无需额外配置。

Starlight 内置 Pagefind 搜索,构建时自动生成。

创建 src/styles/custom.css,在 astro.config.mjs 中引用:

starlight({
customCss: ['./src/styles/custom.css'],
})

更多内容请参考 Astro 官方文档Starlight 文档