文章

Jekyll添加giscus评论系统

Jekyll添加giscus评论系统

准备仓库

  1. 可以选择博客所在的 username.github.io 仓库
  2. 也可以为评论系统单独创建一个仓库

添加 giscus

  1. 安装 giscus

    GitHub Apps - giscus image-20231219160516842

  2. 选择仓库

    image-20231219173549559

  3. 开启 Discussion

    image-20231219161153383

    路径: Setings - General - Features - Discussions

  4. giscus 配置

    语言:简体中文

    仓库: username/username-comments

    页面 ↔️ discussion 映射关系: Discussion 的标题包含页面的 pathname

    Discussion 分类:Announcements

    一般选择 Announcements,因为 Announcements 类型的 discussion 只有管理员才有权限操作,这样便于管理

  5. 查看 giscus 配置

    页面划到底部

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    
     <script src="https://giscus.app/client.js"
            data-repo="username/username-comments"
            data-repo-id="R_sd000001"
            data-category="Announcements"
            data-category-id="DIC_sd000001dfdf"
            data-mapping="pathname"
            data-strict="0"
            data-reactions-enabled="1"
            data-emit-metadata="0"
            data-input-position="bottom"
            data-theme="preferred_color_scheme"
            data-lang="zh-CN"
            crossorigin="anonymous"
            async>
     </script>
    
  6. 配置到 Jekyll

    配置主题:cotes2020/jekyll-theme-chirpy

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    
     comments:
      active: giscus # The global switch for posts comments, e.g., 'disqus'.  Keep it empty means disable
      # The active options are as follows:
      giscus:
        repo: "username/username-comments" # <gh-username>/<repo>
        repo_id: "R_sd000001"
        category: "Announcements"
        category_id: "DIC_sd000001dfdf"
        mapping: "pathname" # optional, default to 'pathname'
        input_position: "bottom" # optional, default to 'bottom'
        lang: "zh-CN" # optional, default to the value of `site.lang`
        reactions_enabled: # optional, default to the value of `1`
    
  7. 效果展示

    image-20231219163018886

参考文档

Hugo 博客引入 Giscus 评论系统 - (lixueduan.com)

使用Jekyll + GitHub Pages搭建个人博客-CSDN博客

本文由作者按照 CC BY 4.0 进行授权