{"slug":"giscus-akismet","title":"你是否在寻找一个评论系统而又不想自托管？又饱受垃圾评论的叨扰？","description":"Giscus就是这样一个很好的评论区，它基于Github Discussion，无需自托管，无需你管理账号，仅需引入一个JS即可用！","coverImage":"https://b.acofork.com/img/giscus-akismet-2025-08-04-12-14-21-image.webp","coverWidth":702,"coverHeight":465,"date":"2025-08-03","tags":["开发"],"pinned":false,"wordCount":884,"html":"<h2 id=\"配置giscus\">配置Giscus</h2><blockquote>\n<p>Giscus使用Github Discussion实现存储用户评论，无需自托管</p>\n</blockquote>\n<p>首先你需要创建一个 <strong>公开仓库</strong> （建议新开一个干净的空仓库）</p>\n<p>然后在仓库设置中 <strong>启用</strong> <code>Discussion</code> 功能</p>\n<p><img src=\"https://b.acofork.com/img/giscus-akismet-2025-08-04-12-16-36-image.webp\" alt=\"\" width=\"770\" height=\"74\" loading=\"eager\" decoding=\"async\" /></p>\n<p>前往 <a href=\"https://giscus.app/zh-CN\" target=\"_blank\" rel=\"noopener noreferrer\">https://giscus.app/zh-CN</a></p>\n<p>首先填写你的仓库，通过检查</p>\n<p><img src=\"https://b.acofork.com/img/giscus-akismet-2025-08-04-12-17-42-image.webp\" alt=\"\" width=\"407\" height=\"269\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>接下来的 <code>映射关系</code> 十分重要！</p>\n<ul>\n<li><p>pathname <strong>（最推荐）</strong>：假如你的文章路径为 <code>posts/helloworld</code> 。那么只要你保证这个路径不变，评论和页面就永远匹配</p>\n</li>\n<li><p>url：只要你换<strong>域名</strong>了，评论和页面就无法匹配</p>\n</li>\n<li><p>title：只要你换<strong>标题</strong>了，评论和页面就无法匹配</p>\n</li>\n</ul>\n<p><img src=\"https://b.acofork.com/img/giscus-akismet-2025-08-04-12-18-21-image.webp\" alt=\"\" width=\"615\" height=\"467\" loading=\"lazy\" decoding=\"async\" /></p>\n<p><strong>需要特别注意的是</strong>：建议 <strong>勾选</strong> <code>使用严格的标题匹配</code> ，<strong>避免评论串台</strong>。开启后，Giscus会根据你选择的映射关系为每一个新的Discussion（新的页面的评论区）插入一个与众不同的 <em>sha1 指纹</em> 。之后的页面评论区与Github Discussion的映射关系都依赖这个哈希字符串，它在每一个Discussion的正文中，以注释形式写入</p>\n<p><img src=\"https://b.acofork.com/img/giscus-akismet-giscus-akismet-1.webp\" alt=\"\" width=\"934\" height=\"369\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>如果你弄丢了或者写错了，Giscus之后将会再创建一个同名的Discussion，并写入正确的哈希</p>\n<p>若旧Discussion并未删除，并想让Giscus命中一个不同的Discussion，你需要根据Giscus默认分配的页面标题（这取决于你上面勾选的映射关系，若勾选pathname，即为 <code>posts/pin</code> ）手动用 <em>sha1</em> 算法算出哈希字符串并手动写入你想要让Giscus映射的Discussion</p>\n<div class=\"markdown-code\" data-language=\"sql\"><div class=\"markdown-code-header\"><span class=\"markdown-code-language\"><svg class=\"code-language-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z\"></path><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"></path><path d=\"M10 9H8\"></path><path d=\"M16 13H8\"></path><path d=\"M16 17H8\"></path></svg><span>sql</span></span><button type=\"button\" class=\"code-block-copy\" aria-label=\"复制代码\" title=\"复制代码\"><svg class=\"code-block-copy-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"></rect><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"></path></svg></button></div><pre><code class=\"hljs language-sql\">root<span class=\"hljs-variable\">@AcoFork</span><span class=\"hljs-operator\">-</span>NAS:<span class=\"hljs-operator\">~</span># echo <span class=\"hljs-operator\">-</span>n \"posts/pin/\" <span class=\"hljs-operator\">|</span> sha1sum\n<span class=\"hljs-number\">6</span>ae1aef4a17c896d06677a8e55c23b364bb82bbb  <span class=\"hljs-operator\">-</span>\nroot<span class=\"hljs-variable\">@AcoFork</span><span class=\"hljs-operator\">-</span>NAS:<span class=\"hljs-operator\">~</span>#</code></pre></div><p>分类推荐选择 <strong>公告（announcements）</strong></p>\n<p><img src=\"https://b.acofork.com/img/giscus-akismet-2025-08-04-12-22-07-image.webp\" alt=\"\" width=\"733\" height=\"213\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>特性按需勾选</p>\n<p><img src=\"https://b.acofork.com/img/giscus-akismet-2025-08-04-12-22-25-image.webp\" alt=\"\" width=\"728\" height=\"302\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>主题按喜好选择。更改后主题会立即呈现</p>\n<p><img src=\"https://b.acofork.com/img/giscus-akismet-2025-08-04-12-22-57-image.webp\" alt=\"\" width=\"394\" height=\"135\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>最后将这段JS复制，放置在你想作为评论区的区块即可</p>\n<p><img src=\"https://b.acofork.com/img/giscus-akismet-2025-08-04-12-23-41-image.webp\" alt=\"\" width=\"737\" height=\"411\" loading=\"lazy\" decoding=\"async\" /></p>\n<h2 id=\"配置akismet\">配置Akismet</h2><blockquote>\n<p>Akismet (Automattic Kismet) 是应用广泛的一个垃圾留言过滤系统，其作者是大名鼎鼎的 WordPress 创始人 Matt Mullenweg，Akismet 也是 WordPress 默认安装的插件，其使用非常广泛，设计目标便是帮助博客网站来过滤垃圾留言。</p>\n</blockquote>\n<p>注册 <a href=\"https://akismet.com/\" target=\"_blank\" rel=\"noopener noreferrer\">akismet.com</a></p>\n<p>选择 Akismet Personal 订阅，将滑块拉到0$，记录得到的 Akismet API Key</p>\n<p><img src=\"https://b.acofork.com/img/giscus-akismet-2025-08-04-12-27-58-image.webp\" alt=\"\" width=\"540\" height=\"563\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>前往 <a href=\"https://github.com/afoim/giscus-fuwari/blob/main/.github/workflows/akismet-comment-check.yml\" target=\"_blank\" rel=\"noopener noreferrer\">https://github.com/afoim/giscus-fuwari/blob/main/.github/workflows/akismet-comment-check.yml</a></p>\n<p>将这个Github Action部署到你的启用了Giscus的仓库</p>\n<p>配置Secret：</p>\n<ul>\n<li><p>AKISMET_API_KEY：你的Akismet API Key</p>\n</li>\n<li><p>GH_TOKEN：前往 <a href=\"https://github.com/settings/tokens\" target=\"_blank\" rel=\"noopener noreferrer\">https://github.com/settings/tokens</a> 创建一个具有 <code>repo</code> <code>write:discussion</code> <code>user</code> 权限的Github个人令牌<img src=\"https://b.acofork.com/img/giscus-akismet-2025-08-04-12-29-06-image.webp\" alt=\"\" width=\"813\" height=\"180\" loading=\"lazy\" decoding=\"async\" /></p>\n</li>\n</ul>\n<p>测试反垃圾是否有效，发送内容为 <code>viagra-test-123</code> 的评论。该评论一定会被当作垃圾评论</p>\n<p>查看Github Action是否做出删评行为</p>\n<p><img src=\"https://b.acofork.com/img/giscus-akismet-2025-08-04-12-30-37-image.webp\" alt=\"\" width=\"598\" height=\"848\" loading=\"lazy\" decoding=\"async\" /></p>\n<h2 id=\"封禁用户\">封禁用户</h2><blockquote>\n<p>如果有人一直刷屏但是反垃圾未检测到？</p>\n</blockquote>\n<p>你可以前往该用户个人信息页面手动封禁它</p>\n<p>详见 <a href=\"https://docs.github.com/zh/communities/maintaining-your-safety-on-github/blocking-a-user-from-your-personal-account#blocking-a-user-from-their-profile-page\" target=\"_blank\" rel=\"noopener noreferrer\">阻止用户访问您的个人帐户 - GitHub 文档</a></p>\n<h2 id=\"防止新用户刷评\">防止新用户刷评</h2><blockquote>\n<p>如果有人一直开小号刷评？</p>\n</blockquote>\n<p>使用 <a href=\"https://github.com/你的用户名/你的仓库/settings/interaction_limits\" target=\"_blank\" rel=\"noopener noreferrer\">https://github.com/你的用户名/你的仓库/settings/interaction_limits</a></p>\n<p>配置临时交互限制，这样新用户就无法对您的存储库进行任何操作</p>\n<p><img src=\"https://b.acofork.com/img/giscus-akismet-2025-08-04-20-43-06-image.webp\" alt=\"\" width=\"794\" height=\"486\" loading=\"lazy\" decoding=\"async\" /></p>\n","toc":[{"id":"配置giscus","text":"配置Giscus","depth":2},{"id":"配置akismet","text":"配置Akismet","depth":2},{"id":"封禁用户","text":"封禁用户","depth":2},{"id":"防止新用户刷评","text":"防止新用户刷评","depth":2}]}