博客添加评论功能

2018-06-03

1.以安装来必力评论为例,大家自己根据实际情况决定。

来必力官网

  • 注册来必力帐号
  • 点击安装-选择city-获取uiduid
    步骤一
    步骤二
    步骤三

2.在themes文件相下找见安装的的主题_config.yml添加如下代码

1
2
3
4
# 添加来比力评论
livere:
on: true
livere_uid: MTAyMC8zNzAxMS8xMzU0Nw

3.在_partial目录下新建liver.ejs文件,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<section class="livere" id="comments">
<!-- 来必力City版安装代码 -->
<div id="lv-container" data-id="city" data-uid="MTAyMC8zNzAxMS8xMzU0Nw==">
<script type="text/javascript">
(function(d, s) {
var j, e = d.getElementsByTagName(s)[0];

if (typeof LivereTower === 'function') { return; }

j = d.createElement(s);
j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
j.async = true;

e.parentNode.insertBefore(j, e);
})(document, 'script');
</script>
<noscript>为正常使用来必力评论功能请激活JavaScript</noscript>
</div>
<!-- City版安装代码已完成 -->
</section>

4.选择评论添加到的位置(文章下面),代码中添加了三种评论选择自己的

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
<% if (page.comments){ %>
<section id="comment">
<!-- <h1 class="title"><%= __('comment') %></h1> -->

<% if(theme.disqus_shortname) { %>
<div id="disqus_thread">
<script type="text/javascript">
var disqus_config = function () {
this.page.url = window.location.href;
this.page.identifier = '<%= page.layout %>-<%= page.slug %>';
this.page.title = '<%= page.title %>';
};
</script>
<noscript>Please enable JavaScript to view the <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>
<% } else if (theme.duoshuo_shortname) { %>
<!-- 多说评论框 start -->
<script type="text/javascript">
var duoshuoQuery = {short_name:"<%= theme.duoshuo_shortname %>"};
(function() {
var ds = document.createElement('script');
ds.type = 'text/javascript';ds.async = true;
ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
ds.charset = 'UTF-8';
(document.getElementsByTagName('head')[0]
|| document.getElementsByTagName('body')[0]).appendChild(ds);
})();
</script>
<div class="ds-thread" data-thread-key="<%= page.layout %>-<%= page.slug %>" data-title="<%= page.title %>" data-url="<%= page.permalink %>"></div>
<!-- 多说评论框 end -->
<% } else if (theme.livere.on) { %>
<!-- 来比力评论框 start -->
<%- partial('livere') %>
<!-- 来比力评论框 end -->
<% } %>
</section>
<% } %>

5.重启服务ok