前言
作为一个完整的博客,评论功能自然是必不可少的。
而可供选择的第三方评论系统有很多,但不是被墙(如Disqus)就是停止服务(如友言、网易云跟帖),或者需要域名备案(如畅言)。
所以只能把目光投向一款来自韩国的评论系统——来必力(livere)。
总的来说,这个评论系统有以下好处:
1.有中文网站
2.界面还算美观
3.国内本土化做得很好,支持如下账号登录:
来必力网站配置
进入官网 https://livere.com ,邮箱注册登录
点击
安装
,选择City免费版,点击现在安装
获得安装代码并复制
- 到此为止,网站的配置到此结束;当然,如果需要修改登录选项和评论界面,可以在设置中更改
博客的配置
- 打开博客主题的配置文件
_config.yml
,加上如下代码:
# Support for LiveRe comments system.
# You can get your uid from https://livere.com/insight/myCode (General web site)
livere_uid:
在
livere_uid:
后加上安装代码中data-uid
的内容,以便以后修改打开博客主题的
layout
文件夹在
includes
文件夹中新建一个livere.swig
文件,在其中写入如下代码:
{% if not (theme.duoshuo and theme.duoshuo.shortname) and not theme.duoshuo_shortname and not theme.disqus_shortname and not theme.hypercomments_id and not theme.gentie_productKey %}
{% if theme.livere_uid %}
<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>
{% endif %}
{% endif %}
- 打开
post.swig
文件,在</article>
前加上如下代码:
{% if page.photos.length %}
{% include 'includes/gallery.swig' %}
{% endif %}
{% autoescape false %}{{ page.content }}{% endautoescape %}
{% if theme.livere_uid %}
<div id="lv-container" data-id="city" data-uid="{{ theme.livere_uid }}"></div>
{% endif %}
在
</article>
后加上{% raw %}{% include 'includes/livere.swig' %}{% endraw %}
最后,将博客重新deploy即可
BUG!!!
在写完这篇博客后,再hexo g
发生错误,提示Template render error:(unknown path)
,后经google发现,hexo对特殊符号{% raw %}{% %}{% endraw %}
和{% raw %}{{ }}{% endraw %}
的解析有错误,其被当成hexo模板中的标签,所以出现错误无法找到路径includes/livere.swig
目前的解决办法为在这两个特殊字符之外添加如下代码:
{% raw %}
特殊字符
{% endrow %}
使hexo不解析其中的特殊字符
同时注意,对于用三个`包围的代码块则不存在这样的问题