renshixin's blog — 基于 Typst 的静态博客,使用自定义 Node.js 构建脚本生成 HTML。
# 构建网站(4 并发)
npm run build:fast
# 本地预览(端口 11451)
npm run serve浏览器打开 http://localhost:11451 即可预览。
| 命令 | 说明 |
|---|---|
npm run build |
单线程构建 |
npm run build:fast |
4 并发构建 |
npm run build:preview |
构建到 _site-preview |
npm run build:preview_fast |
4 并发构建到 _site-preview |
CLI 选项:-o 输出目录、-f 强制全量构建、-j 并发数、-h 帮助。
├── posts/ # 博客文章(每篇一个目录,含 index.typ)
├── pages/ # 独立页面(首页、关于、归档、标签、分类)
├── assets/ # 静态资源(CSS、JS、图标)
├── lib/ # 构建脚本与 Typst 模板库
├── config.typ # 主题与导航配置
├── site.config.json# 站点元数据(RSS、标题、作者)
└── _site/ # 构建产物(已 gitignore)
在 posts/ 下新建目录,创建 index.typ,参考已有文章的格式编写即可。
本博客在每篇文章页底部使用 Giscus,把评论以 GitHub Discussions 的形式存在一个 public 仓库里。相比 Gitalk,Giscus 走 GitHub App 授权,不再需要任何 OAuth Client Secret,全部配置项都是公开值。一次性配置四步即可启用:
-
开启 Discussions:在评论仓库(默认
xiaohongrsx/blog-comments)的Settings → General → Features里勾上Discussions。 -
新建评论分类:进入该仓库
Discussions标签页,右上角设置图标 →New category,名字填Comments,类型选Announcement(只允许维护者发起话题,可有效防止灌水)。 -
安装 Giscus App:访问 github.com/apps/giscus 把 Giscus 安装到评论仓库(限定到这个仓库即可,无需授权所有仓库)。
-
抓取
repoId/categoryId:访问 giscus.app/zh-CN 配置生成器,仓库填xiaohongrsx/blog-comments,Mapping 选Pathname,Discussion Category 选Comments;页面下方生成的<script>标签里复制data-repo-id与data-category-id的值,填到site.config.json:{ "giscus": { "repo": "xiaohongrsx/blog-comments", "repoId": "<从 giscus.app 抓到的 repoId>", "category": "Comments", "categoryId": "<从 giscus.app 抓到的 categoryId>", "mapping": "pathname", "strict": "0", "reactionsEnabled": "1", "emitMetadata": "0", "inputPosition": "bottom", "lang": "zh-CN" } }
完成后重新跑一次 npm run build:fast,构建脚本会把这份配置写到 _site/assets/core/giscus.config.js,文章页加载时会自动初始化评论组件。repoId 或 categoryId 为空时,前端只会在控制台打 warn,不会渲染评论框,方便本地调试。
备注:
repoId/categoryId是 GitHub GraphQL 暴露的对象 ID,本身就是公开可枚举的值,不会触发 GitHub Secret Scanning 告警,也不存在密钥泄露问题。主题切换通过监听<html>的data-theme属性走postMessage实时同步给 Giscus iframe,无需重载页面。
推送到 main 分支后,GitHub Actions 自动构建并部署到 GitHub Pages。