
注意:
1.callback URL需要填自己的博客地址 eg:https://d0ma4t2.github.io/
2.然后你会得到一个Client ID 和一个 Client secret,这个将被用于之后的用户登录
在yelee主题中引入Gitment
在themes/yelee/layout/_partial/post文件夹下创建git.ejs文件,并写入下边代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <div id="git"></div> <link rel="stylesheet" href="https://billts.site/extra_css/gitment.css"> <script src="https://billts.site/js/gitment.js"></script> <script> var gitment = new Gitment({ id: "<%= page.title %>", owner: "stven0king",//github用户名 repo: "stven0king.github.io",//用户存储评论的github项目名称 oauth: { id: "<%= page.title %>", client_id: "xxxxxxxxxxxxxxxxxxxxxxxx",//注册OAuth Application时生产的ClinetID client_secret:"xxxxxxxxxxxxxxxxxxxxx",//注册OAuth Application时生成的Client Secret }, }) gitment.render('git') </script> <!-- Gitment代码结束 -->
|
接着在themes/yelee/layout/_partial/article.ejs文件中找到
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <% 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 }) %> <% } %> <% } %>
|
在这个节点下添加:
1 2 3 4 5 6 7
| <% if (!index){ %> <% if (post.comments){ %> <%- partial('post/git') %> <% } else { %> <div class="git"></div> <% } %> <% } %>
|
以上所有操作完成后,hexo clean、hexo g -d,然后文章底部就可以展现评论视图了
FAQ
1.最开始我们看到的是:Error:Comments Not Initialized,登录你的账号即可
2.点击初始化评论
3.配置好后,有时候出现object ProgressEvent,可能是网络问题关掉网页重新打开即可
4.关于hexo博客自定义域名后gitment评论系统登陆出现redirect error返回主页的解决办法
https://www.cnblogs.com/zmj97/p/10421872.html
本文参考:
https://www.dazhuanlan.com/2020/01/20/5e2518040b423/
https://blog.csdn.net/xiaosongshine/article/details/100614850?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task
https://blog.csdn.net/YEN_CSDN/article/details/80142392?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task