首页 技术 正文
技术 2022年11月16日
0 收藏 372 点赞 4,817 浏览 3373 个字

关于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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,556
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,405
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898