评论、搜索与联系表单集成
原 WordPress 主题的评论、搜索、联系表单在 Hugo 中由第三方服务替代,全部通过
config.toml 开关控制,未启用时页面不含任何相关脚本(性能优先)。
| 功能 | 方案 | 默认 |
|---|---|---|
| 评论 | Giscus / Utterances | 关闭 |
| 搜索 | Pagefind | 开启 |
| 联系表单 | Formspree / Netlify Forms | 关闭 |
评论:Giscus(推荐)
一次性准备(GitHub 侧)
- 仓库设为公开;
- Settings → General → Features → 开启 Discussions;
- 安装 giscus App:https://github.com/apps/giscus → Configure → 选择该仓库。
生成配置
打开 https://giscus.app/zh-CN,选择仓库与分类,复制生成的配置填入:
1[params.comments]
2 provider = "giscus"
3 repo = "你的用户名/你的仓库"
4 repoId = "R_kgDOxxxxxxx"
5 category = "Announcements"
6 categoryId = "DIC_kwDOxxxxxxx"
7 theme = "light" # 或 dark;勿用 preferred_color_scheme(SSR 缺陷)
排查:页面报 “giscus is not installed” → App 未安装/仓库非公开/Discussions 未开启; 控制台 MIME 报错 → theme 用了非法值。
Utterances 替代
只需 repo 与 theme(github-light / github-dark)两个字段,其余照抄
utteranc.es 即可。