Skip to content

[Gitalk]评论系统

NexT集成了多种评论系统,当前使用Gitalk

简介

gitalk是一个基于github开发的评论插件,它将文章评论以issues形式保存在github仓库中

实现步骤如下:

  1. 注册github应用
  2. NexT配置

注册github应用

进入github注册页面:Register a new OAuth application

  • Application name:应用名,方便起见直接填github用户名
  • Homepage URL:网站地址
  • Application description:应用描述
  • Authorization callback URL:网站地址

注册成功后会生成Client IDClient Secret

NexT配置

修改主题_config.yml


# Gitalk
# For more information: https://gitalk.github.io
gitalk:
  enable: true
  github_id: zjykzj # GitHub repo owner
  repo: guestbook # Repository name to store issues
  client_id: e15xxxxx63dce # GitHub Application Client ID
  client_secret: 76cxxxxxf766 # GitHub Application Client Secret
  admin_user: zjykzj # GitHub repo owner and collaborators, only these guys can initialize gitHub issues
  distraction_free_mode: true # Facebook-like distraction free mode
  # When the official proxy is not available, you can change it to your own proxy address
  proxy: https://cors-anywhere.herokuapp.com/https://github.com/login/oauth/access_token # This is official proxy adress
  # Gitalk's display language depends on user's browser or system environment
  # If you want everyone visiting your site to see a uniform language, you can set a force language value
  # Available values: en | es-ES | fr | ru | zh-CN | zh-TW
  language: zh-CN
  • 设置enabletrue
  • github_id填入github帐号
  • repo填入github仓库名(注意:是仓库名不是仓库地址),评论将会以issues形式保存在该仓库下
  • client_id填入注册生成的值
  • client_secret填入注册生成的值
  • admin_user填入github帐号,用于初始化评论账户

Error: Not Found

问题描述:在文章底部评论框中出现错误信息

Error: Not Found

解决:和配置选项的填写有关,注意填写的内容

隐藏评论框

设置gitalk评论系统后,将会在每篇文章末尾添加评论框,而对于标签页/类别页等不需要评论的文章,可在front-matter设置属性进行隐藏

comments: false

Error: Request failed with status code 403

这是由于代理服务器出错的问题,经过查询,发现是NexT提供的反向代理已停止服务

  # When the official proxy is not available, you can change it to your own proxy address
  proxy: https://cors-anywhere.herokuapp.com/https://github.com/login/oauth/access_token # This is official proxy adress
  # Gitalk's display language depends on user's browser or system environment

当前的解决方案就是自己新建一个反向代理服务器,启动nginx服务,配置如下:

   location = /login/oauth/access_token {
       add_header Access-Control-Allow-Origin 'https://xxx.xxx.xxx';
       add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
       add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
       if ($request_method = 'OPTIONS') {
             return 204;
       }
       proxy_pass https://github.com;
   }

自定义反向代理以重定向github地址,使用如下地址进行替换:

https://xxx.xxx.xxx/login/oauth/access_token

相关阅读