嗯。。又换了个评论系统

步骤

主要还是因为我比较懒,而且valine的后台是在太难弄了。所以还是换成了第三方的评论系统Gitalk

  • 首先在这里注册一个Github OAuth application

  • 在Yelee主题目录下的_config.yml中添加
gitalk:
  on: true
  clientID: 'your clientID'
  clientSecret: 'your clientSecret'
  repo: 'attack204.github.io' # 仓库地址
  owner: 'attack204' # 拥有者
  admin: ['attack204'] # admin 用户
  • _partial/comments下创建gitalk.ejs

注意!下面的id选项中如果按照原式方法填的话会出现Error: Validation Failed的问题

一个比较好的解决思路是直接填写id: '<%= page.title %>'

<section id='comments' style='margin: 2em; padding: 2em; background: rgba(255, 255, 255, 0.5)'>
  <link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">
  <script src="https://unpkg.com/gitalk@latest/dist/gitalk.min.js"></script>
  <div id="gitalk-container"></div>
  <script type="text/javascript">
    var gitalk = new Gitalk({
      clientID: '<%= theme.gitalk.clientID %>',
      clientSecret: '<%= theme.gitalk.clientSecret %>',
      repo: '<%= theme.gitalk.repo %>',
      owner: '<%= theme.gitalk.owner %>',
      admin: ['<%= theme.gitalk.owner %>'],
      id: window.location.pathname
    })
    gitalk.render('gitalk-container')
  </script>
</section>
  • 修改 _partial/article.ejs
 <% if (!index && post.comments){ %>
    <% if (theme.duoshuo.on) { %>
      <%- partial('comments/duoshuo', {
          key: post.path,
          title: post.title,
          url: config.url+url_for(post.path),
          }) %>
    <% } else if (theme.youyan.on) { %>
        <%- partial('comments/youyan') %>
    <% } else if (theme.disqus.on) { %>
        <%- partial('comments/disqus', {
            shortname: theme.disqus.shortname
          }) %>
    <% } else if (config.disqus_shortname) { %>
        <%- partial('comments/disqus', {
            shortname: config.disqus_shortname
          }) %>
    <% } else if (theme.valine.on) { %>
        <%- partial('comments/valine', {
          key: post.slug,
          title: post.title,
          url: config.url+url_for(post.path)
        }) %>
+   <% } else if (theme.gitalk.on) { %>
+       <%- partial('comments/gitalk') %>
    <% } %>
<% } %>

参考资料

更换博客评论系统