Gitment 是作者imsun实现的一款基于 GitHub Issues 的评论系统. 支持在前端直接引入, 不需要任何后端代码. 可以在页面进行登录, 查看, 评论, 点赞等操作. 同时有完整的 Markdown / GFM 和代码高亮支持. 尤为适合各种基于 GitHub Pages 的静态博客或项目页面.

这篇文章仅介绍如果在 hexo-NexT 中添加 Gitment 评论插件, 并且增加一个点开显示评论的按钮, 对于 Gitment 的使用请参考 imsun 的博客.

另外, 本教程的按钮样式和代码均直接取自 ehlxr 博主.

“显示 Gitment 评论” 的按钮样式

在 next/source/css/_common/components 目录中新建一个 gitment.styl 的 css 样式文件, 复制以下代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
.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;
}

然后打开同目录中的 components.styl 文件, 找个顺眼的位置添加一句

1
@import "gitment"

添加 Gitment 插件

打开 /next/layout/_partials/comments.swig 文件, 在最后一个 elseif 代码块下面添加 Gitment 的内容.

例如我的就是这样

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
... // 上面内容省略了..
{% elseif theme.changyan.appid and theme.changyan.appkey %}
<div id="SOHUCS"></div>
{% elseif theme.gitment.enable %}
<div onclick="showGitment()" id="gitment_title" class="gitment_title">显示 Gitment 评论</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>
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: window.location.pathname,
theme: myTheme,
owner: '{{ theme.gitment.owner }}',
repo: '{{ theme.gitment.repo }}',
oauth: {
client_id: '{{ theme.gitment.client_id }}',
client_secret: '{{ theme.gitment.client_secret }}'
}
});
gitment.render('container');
}
</script>
{% endif %}

然后打开 NexT 主题的 _config.yml 文件, 在评论相关设置的区域添加下面的代码, 并根据 Gitment 文档说明来添加相应的值

1
2
3
4
5
6
7
8
# Gitment comments
gitment:
enable: true
owner: xxxx
repo: xxxx
client_id: xxxx
client_secret: xxxx
lazy: true

lazy属性为是否直接显示评论模块,true会显示”显示评论”按钮,false会直接显示

为 hexo NexT 添加 Gitment 评论插件的更多相关文章

  1. Gitment评论插件的使用

    前言 继上一篇的 GitPages部署自己的网站 现在开始添加博客的评论插件Gitment.这里的话我是使用hexo添加gitment插件,如果不是使用hexo,请到官网指定这里. 开始 第一步 注册 ...

  2. 为博客添加 Gitalk 评论插件

    背景 Disqus需要翻墙才能正常使用 畅言有广告 2种评论系统都很难统一管理 优化 使用Gitalk评论插件 , gitalk 使用 Github 帐号登录,界面干净整洁,支持 MarkDown语法 ...

  3. Hexo博客yilia主题添加Gitment评论系统

    一开始搭建hexo+yilia博客使用的评论功能是通过来必力实现的.来必力免费,功能多,一开始的体验效果很好,但是后来打开网站发现来必力加载的越来越慢(来必力是韩国的公司,可能是国内限制),遂打算换一 ...

  4. blog 社会化评论插件 多说for china, disqus for global range

    1.disqus https://disqus.com/ https://publishers.disqus.com/engage https://disqus.com/admin/create/ h ...

  5. 号外号外!解决github+hexo+yilia评论插件的问题!!!

    先走一波效果图!    本人网站--http://www.wenzheng.club/ ps:效果还是不错的,支持QQ微信登录,支持表情,甚至gif动图评论! 插件采用韩国服务器的来必力评论插件--h ...

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

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

  7. Hexo Next配置百度分享、加入动态背景、接入网页在线联系功能、页脚增加统计功能、添加gitment、添加热度、阅读量排行

    Hexo Next配置百度分享.加入动态背景.接入网页在线联系功能.页脚增加统计功能.添加gitment.添加热度.阅读量排行: https://wangc1993.github.io/categor ...

  8. 关于hexo博客自定义域名后gitment评论系统登陆出现redirect error返回主页的解决办法

    title: 关于hexo博客自定义域名后gitment评论系统登陆出现redirect error返回主页的解决办法 toc: false date: 2018-04-16 22:57:50 cat ...

  9. github page博客里添加多说评论插件

    本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuirong.cn 摘要: 由于现在我这个博客原来用的是DISQUS评论插件,那全是全球 ...

随机推荐

  1. Windows系列之(一):Windows10 上运行Ubuntu Bash

    1. 前言 2016年4月6日,Windows 10 Insider Preview 发布的版本 14316,添加了Ubuntu Bash,在Windows上提供一个Linux环境,可以直接执行Lin ...

  2. POP3_使用SSL链接邮箱并获取邮件

    Gmail目前已经启用了POP3和SMTP服务,与其他邮箱不同的是Gmail提供的POP3和SMTP是使用安全套接字层SSL的,因此常规的JavaMail程序是无法收发邮件的,下面是使用JavaMai ...

  3. 大型电商业务架构 IT大咖说 - 大咖干货,不再错过

    大型电商业务架构 IT大咖说 - 大咖干货,不再错过 http://www.itdks.com/dakashuo/new/dakalive/detail/591

  4. Sed&awk笔记之sed篇(转)

    Sed是什么 <sed and awk>一书中(1.2 A Stream Editor)是这样解释的: Sed is a "non-interactive" strea ...

  5. getRequestURI,getRequestURL的区别(转)

    test1.jsp======================= <a href ="test.jsp?p=fuck">跳转到test2</a> test2 ...

  6. An Isolated DAC Using PWM Output

    An Isolated DAC Using PWM Output Arduino‘s (ATmega328P) PWM outputs via analogWrite can be convenien ...

  7. USBDM BDM Interface for Freescale Microcontroller -- Firmware

    USBDM BDM Interface for Freescale Microcontroller -- Firmware BDM firmware for USBDM BDMs Refer to s ...

  8. Canbus ID filter and mask

    Canbus ID filter and mask CANBUS is a two-wire, half-duplex, bus based LAN system that is ‘collision ...

  9. python及扩展程序安装

    安装 从官方网站下载python程序,我下载的是python-3.3.2.msi 然后下载python扩展程序,我下载的是pywin32-218.win32-py3.3.exe 最后下载wmi插件,我 ...

  10. systemtap 调试postgrel

    http://blog.163.com/digoal@126/blog/static/16387704020137140265557/   dtrace http://blog.163.com/dig ...