如何添加评论功能

使用Gitalk做为系统评论

Posted by Ryan on 2025-04-16
Estimated Reading Time 2 Minutes
Words 465 In Total
Viewed Times

评论系统设置

Hexo-Theme-LiveMyLife 主题暂时支持三种评论方式。我使用 gitalk 为默认评论系统。

Gitalk

Gitalk 是基于 GitHub Issue 和 Preact 的现代化的评论组件。 有关详细的配置方法,请参考 Gitalk 官方文档。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Gitalk Settings
# Doc: https://github.com/gitalk/gitalk/blob/master/readme-cn.md
gitalk:
owner: # 'GitHub repo owner'
admin: # ['GitHub repo owner and collaborators, only these guys can initialize github issues']
repo: # 'GitHub repo'
clientID: # 'GitHub Application Client ID'
clientSecret: # 'GitHub Application Client Secret'
perPage: 10 # Pagination size, with maximum 100.
pagerDirection: last # Comment sorting direction, available values are last and first.
createIssueManually: false # By default, Gitalk will create a corresponding github issue for your every single page automatically when the logined user is belong to the admin users. You can create it manually by setting this option to true
language: en # Localization language key, en, zh-CN and zh-TW are currently available.
maxCommentHeight: 250 # An optional number to limit comments' max height, over which comments will be folded.Default 250.
proxy: https://cors-anywhere.azm.workers.dev/https://github.com/login/oauth/access_token # GitHub oauth request reverse proxy for CORS. For example, the demo url is 'https://cors-anywhere.herokuapp.com/https://github.com/login/oauth/access_token'.You should deploy your own proxy url as in this issue https://github.com/gitalk/gitalk/issues/429.
  • 说明 :
    • ownner:要填写你的github的用户信息,比如我的github的用户为 tigergo001,则配置为 ownner: tigergo001
    • admin: 填写同ownner的填写,例如配置为: admin: tigergo001
    • repo: 仓库的填写可以是一个新建的公共仓库,也可以是githu pages的仓库的地址,以我github pages的地址为例,配置为repo: tigergo001.github.io
    • clientID 和 clientSecret 是github Apps的配置信息,申请地址具体的配置如下
      • 访问 GitHub → Settings → Developer settings → OAuth Apps → 注册新应用
      • 回调地址填写博客域名(如 https://tiger.com)‌
      • 保存生成的 Client IDClient Secret(密钥是一次性的,切记要复制后保存到自己想要保存的地方)

经过以上的配置后,你就可以使用gitalk来实现评论系统了。


如果您喜欢此博客或发现它对您有用,则欢迎对此发表评论。 也欢迎您共享此博客,以便更多人可以参与。 如果博客中使用的图像侵犯了您的版权,请与作者联系以将其删除。 谢谢 !