为hexo博客添加基于gitment评论功能

时间:2022-09-03 14:37:24

关于gitment

gitment其实就是利用你的代码仓库的Issues,来实现评论。每一篇文章对应该代码仓库中的

一个Issues,Issues中的评论对应你的博客每篇文章中的评论。如果你是用github的博客的话

用起来将会十分的方便。

注册github应用

首先需要在这注册一个OAuth Application, 请戳此处。在注册的过程中,你需要输入以下的东西:

Application name 随意就好

Homepage URL 你的博客地址,例如https://detectivehlh.github.io/

Application description 随意就好

Authorization callback URL 也是博客地址,例如https://detectivehlh.github.io/

输入完成之后,点击注册就OK了。成功之后就会拿到Client IDClient Secret,然后先进行一下步,暂时还不会用到这个。

修改主题配置文件

下一步就是要修改你的博客所使用的主题的配置文件。定位到# Comments,添加如下代码。

gitment:
enable: true
mint: true
count: true
lazy: false
cleanly: false
language:
github_user: detectiveHLH
github_repo: detectiveHLH.github.io
client_id: xxx
client_secret: xxx
proxy_gateway:
redirect_protocol:

将上面代码的github_user和github_repo改成你自己的就可以了。

为gitment添加样式和layout

打开你所使用的主题的目录。打开layout/_partial/comments.ejs,在原文件后加入如下代码。

<% if(theme.gitment.enable) { %>
<div id="gitment_title" class="gitment_title"></div>
<div id="container" style="display:none"></div>
<link rel="stylesheet" href="https://imsun.github.io/gitment/style/default.css">
<script src="https://imsun.github.io/gitment/dist/gitment.browser.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
const myTheme = {
render(state, instance) {
const container = document.createElement('div');
container.lang = "en-US";
container.className = 'gitment-container gitment-root-container';
container.appendChild(instance.renderHeader(state, instance));
container.appendChild(instance.renderEditor(state, instance));
container.appendChild(instance.renderComments(state, instance));
container.appendChild(instance.renderFooter(state, instance));
return container;
}
} function showGitment() {
$("#gitment_title").attr("style", "display:none");
$("#container").attr("style", "").addClass("gitment_container");
var gitment = new Gitment({
id: decodeURI(window.location.pathname),
theme: myTheme,
owner: 'detectiveHLH',
repo: 'detectiveHLH.github.io',
oauth: {
client_id: 'xxx',
client_secret: 'xxx'
}
});
gitment.render('container');
} showGitment();
</script>
<% } %>

将上面代码中的owner、repo、oauth中的信息换成你自己的就可以了,client_id和client_secret

就是第一步申请github应用得到的。我查了网上很多教程,都是需要点击按钮才能显示评论,我

做了一点改动,引用之后可以直接的显示评论。然后打开source/css/_partial/_gitment.styl,如果没有就新建文件。添加如下代码。

.gitment_title:hover {
color: #fff;
background: #0a9caf;
background-image: initial;
background-position-x: initial;
background-position-y: initial;
background-size: initial;
background-repeat-x: initial;
background-repeat-y: initial;
background-attachment: initial;
background-origin: initial;
background-clip: initial;
background-color: rgb(10, 156, 175);
}
.gitment_title {
border: 1px solid #0a9caf;
border-top-color: rgb(10, 156, 175);
border-top-style: solid;
border-top-width: 1px;
border-right-color: rgb(10, 156, 175);
border-right-style: solid;
border-right-width: 1px;
border-bottom-color: rgb(10, 156, 175);
border-bottom-style: solid;
border-bottom-width: 1px;
border-left-color: rgb(10, 156, 175);
border-left-style: solid;
border-left-width: 1px;
border-image-source: initial;
border-image-slice: initial;
border-image-width: initial;
border-image-outset: initial;
border-image-repeat: initial;
border-radius: 4px;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
border-bottom-left-radius: 4px;
}
.gitment_title {
display: inline-block;
padding: 0 15px;
padding-top: 0px;
padding-right: 15px;
padding-bottom: 0px;
padding-left: 15px;
color: #0a9caf;
cursor: pointer;
font-size: 14px;
}

然后打开source/css/style.styl,在原有文件后面添加如下代码,引入gitment相关的样式。

@import "partial/_gitment.styl"

结束

到此为止,更新你的博客。就可以看到评论了。

个人博客传送门 detectiveHLH

github传送门 detectiveHLH

为hexo博客添加基于gitment评论功能的更多相关文章

  1. 【干货】2个小时教你hexo博客添加评论、打赏、RSS等功能 &lpar;转&rpar;

    备注:该教程基于Hexo 2.x版本,目前Hexo是3.x版本,照本教程实现有可能会出现404错误,笔者目前还未找时间去解决,待笔者找时间解决该问题后,再写一篇该问题的解决教程,给各位读者带来困扰,还 ...

  2. hexo博客添加gitalk评论系统

      经过了一天的折腾,我终于为自己的博客添加上了评论系统.坦率的讲,为什么网上那么多方案我还要自己写一篇博客,那就是因为他们说的都有bug,所以我要自己总结一下.   我选用的是gitalk评论系统, ...

  3. 为你的CSDN博客添加CNZZ流量统计功能

    一.流量统计介绍 流量统计是指通过各种科学的方式,准确的纪录来访某一页面的访问者的流量信息,目前而言,必须具备可以统计. 1.简介 统计独立的访问者数量(独立用户.独立访客): 可以统计独立的IP地址 ...

  4. Hexo博客添加SEO-评论系统-阅读统计-站长统计

    原文地址:→传送门 写在前面 在五月出捣腾了一把个人博客,但是刚开始只做了一些基础设置,套路也没摸清,基础安装篇请看hexo从零开始到搭建完整,里面讲到了基础工具的安装及blog项目的文件夹含义,以及 ...

  5. hexo博客添加功能

    设置Hexo主题模式 Hexo主题中,有三种不同的模式,通过切换模式,让NexT主题显示不一样的样式.在NexT根目录下有一个同样名称为_config.yml,为了区分hexo根目录下的_config ...

  6. 利用Github Pages创建的Jekyll模板个人博客添加阅读量统计功能

    目录 前言 准备工作 模板文件修改 写在最后 内容转载自我自己的博客 @(文章目录) 前言 Jekyll 是一个简单的免费的 Blog 生成工具,类似 WordPress .它只是一个生成静态网页的工 ...

  7. &lbrack;转&rsqb;Hexo博客添加访问统计 - 记录

    引入不蒜子 <script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"> ...

  8. Hexo博客搭建以及Next主题美化的经验之谈

    这并不是一篇博客搭建教程.内容主要包含个人对于Hexo博客搭建的心得,Next6.0主题美化的部分建议,以及摘录一些各种用于博客搭建的link. 在博客园3年6个月,确实也学到了很多,博客园也是目前为 ...

  9. Hexo 博客 之 腾讯云部署过程

    写在前面 Hexo 博客搭好了有差不多两周时间了,这期间走了很多弯路,跳了很多坑.一些坑自己 bing 到了答案,找到了解决方法,一些坑则是自己摸索出来的解决方法.现在准备写几篇关于搭建流程.搭建过程 ...

随机推荐

  1. bzoj2179&colon; FFT快速傅立叶

    #include <iostream> #include <cstdio> #include <cstring> #include <algorithm&gt ...

  2. &lbrack;转&rsqb;大型 JavaScript 应用架构中的模式

    目录 1.我是谁,以及我为什么写这个主题 2.可以用140个字概述这篇文章吗? 3.究竟什么是“大型”JavaScript应用程序? 4.让我们回顾一下当前的架构 5.想得长远一些 6.头脑风暴 7. ...

  3. UIView添加支持代码块的手势

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(a ...

  4. 【转】(总结)Linux下su与su -命令的本质区别

    原文网址:http://www.ha97.com/4001.html 本人以前一直习惯直接使用root,很少使用su,前几天才发现su与su -命令是有着本质区别的! 大部分Linux发行版的默认账户 ...

  5. angular 自定义filter

    用modul.filter .filter("fiilterCity",function(){ return function(obj){ var newObj = []; ang ...

  6. 【Android Developers Training】 13&period; 支持不同平台版本

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

  7. 读书笔记 - reword &lpar;重来&rpar;

    reword (重来) 虽然我是一个不是很喜欢看书的人,但是公认的是看书对提高个人的水平是很有帮助的. 而且我想,如果我要写一本书,我一定会经过多次校验.经过长时间思考确保无误后才会出版的.所以我想看 ...

  8. 安利一款强大的学习软件XMind&lpar;顺便放上这几天制作的JavaSE的思维导图day1-day4&rpar;

    最近在学习Java,并且在使用一款非常酷炫无敌吊炸天的软件,思维导图制作神器-XMind,然后就像分享给大家,至于XMind是什么大家自行百度,在这里我就不赘述了 我这里说下我认为的好的实用的常用快捷 ...

  9. Postgresql插入或更新操作upsert

    幂等性的一个要求是多次操作的结果一致.对于update操作,多次直接的结果都是最后update的值,是满足需求的. 但对于insert,如果已经插入,第二次会报错,duplicate error, 主 ...

  10. NCBI News

    NCBI淘汰序列GI - 使用Accession.Version代替! 截至2016年9月,被称为“GI”的整数序列标识符将不再包括在NCBI支持的序列记录的GenBank,GenPept和FASTA ...