hexo博客配置-添加评论系统-gitment和valine-需注册

本文所用的架构或思路参考该文:hexo博客配置-主题管理与配置

配置方案

安装参考如下即可——注意有坑,请继续往下看。这里LeanCloud的登录用github来注册登录即可。

hexo部署github和gitment操作简单介绍

object ProgressEvent

hexo博客评论新神器——Valine

Valine – 一款极简的评论系统

使用gitment,要先在评论区登录github,否则显示Error: Comments Not Initialized(中文显示评论不可用之类);登录后点击Initialize Comments。另外可能会报错[object ProgressEvent]或者gh-oauth.imsun.net链接不上。这是因为gh-oauth.imsun.net网站证书失效了!解决方法:

方案一:单独访问这个网站https://gh-oauth.imsun.net/,加入例外,允许浏览器访问。但这个方案,别人看你博客的人不一定知道要加,所以不好。

方案二:更改node_modules/gitment/dist/gitment.jshttps://gh-oauth.imsun.net,直接改为请求 github 认证的接口https://github.com/login/oauth/access_token

参考:imsun/gitment/issues#102,gitment评论模块接入hexo

使用双评论系统

此处用了gitment(稳定)和Valine(方便)。可以对themes/hexo-theme-next/layout/_partials/comments.swigif-else语句稍微修改即可。我的改完后长这样:

comments.swigview raw
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
51
52
53
54
55
{% if page.comments %}

{% if theme.facebook_sdk.enable and theme.facebook_comments_plugin.enable %}
<div class="comments" id="comments">
<div class="fb-comments"
data-href="{{ page.permalink }}"
data-numposts="{{ theme.facebook_comments_plugin.num_of_posts }}"
data-width="{{ theme.facebook_comments_plugin.width }}"
data-colorscheme="{{ theme.facebook_comments_plugin.scheme }}">
</div>
</div>

{% elseif theme.vkontakte_api.enable and theme.vkontakte_api.comments %}
<div class="comments" id="comments">
<div id="vk_comments"></div>
</div>

{% elseif theme.disqus.enable %}
<div class="comments" id="comments">
<div id="disqus_thread">
<noscript>
Please enable JavaScript to view the
<a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
</noscript>
</div>
</div>

{% elseif theme.livere_uid %}
<div class="comments" id="comments">
<div id="lv-container" data-id="city" data-uid="{{ theme.livere_uid }}"></div>
</div>

{% elseif theme.changyan.enable and theme.changyan.appid and theme.changyan.appkey %}
<div class="comments" id="comments">
<div id="SOHUCS"></div>
</div>

{% elseif theme.gitment.enable %}
<div class="comments" id="comments">
{% if theme.gitment.lazy %}
<div onclick="showGitment()" id="gitment-display-button">{{ __('gitmentbutton') }}</div>
<div id="gitment-container" style="display:none"></div>
{% else %}
<div id="gitment-container"></div>
{% endif %}
</div>

{% endif %}

{% if theme.valine.enable and theme.valine.appid and theme.valine.appkey %}
<div class="comments" id="comments">
</div>
{% endif %}

{% endif %}

顺带添加LeanCloud文章阅读量统计(待验证是否可行)

就是在配置Valine的同时,创建一个class,名叫“Counter”,这样可以和Valine共用一个app了。

其他参考:

Hexo(NexT 主题)评论系统哪个好?

Hexo-NexT主题添加评论功能(来必力、Hypercomments、畅言、友言)

Donate comment here
xiaotiandi 微信支付

微信支付

xiaotiandi 支付宝

支付宝

xiaotiandi

公益(commonweal)微信