Hexo博客 添加评论功能 (来必力 livere)& Template render error (Hexo BUG)

前言

作为一个完整的博客,评论功能自然是必不可少的。

而可供选择的第三方评论系统有很多,但不是被墙(如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不解析其中的特殊字符

同时注意,对于用三个`包围的代码块则不存在这样的问题

原文地址

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值