美文网首页hexo
为next添加友言评论支持

为next添加友言评论支持

作者: 思_路 | 来源:发表于2016-12-27 22:32 被阅读4295次

背景

最近多说经常莫名其妙的挂掉,而且也无法进行新站点的注册,总提示服务错误,请联系客服的信息,被逼无奈,只能转战其他的第三方评议平台,目前next官方只支持多说disqus,而disqus在国外,国内访问相对来说比较慢,在我家里的网络条件下,如果不翻墙,根本打不开,极大地影响了用户体验。

所以,自已动手,丰衣足食。简单地研究了一下next的目录以后,便开始开发友言的评论模块。

第一步,注册友言,添加新的站点

  • 打开 友言 的官网,注册新用户,并登录。
注册页面
  • 获取代码


第二步开始改造

(1). 在目录thems/next/layout/_scripts/third_party/comments下添加友言的模块文件youyan.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.youyan_uid %}
      {% set uid = theme.youyan_uid %}
    {% endif %}

   {% if page.comments %}
        <!-- UY BEGIN -->
        <script type="text/javascript" src="http://v2.uyan.cc/code/uyan.js?uid={{uid}}"></script>
        <!-- UY END -->
    {% endif %}
  {% endif %}

(2). 修改thems/next/layout/_scripts/third_party/comments.swig文件,添加友言脚本的引用。

{% include './comments/duoshuo.swig' %}
{% include './comments/disqus.swig' %}
{% include './comments/youyan.swig' %}
{% include './comments/hypercomments.swig' %}
{% include './comments/gentie.swig' %}

(3). 修改themes/next/layout/_partials/comments.swig文件,在endif之前添加友言的div

   {% if page.comments %}
     <div class="comments" id="comments">
       {% if (theme.duoshuo and theme.duoshuo.shortname) or theme.duoshuo_shortname %}
         <div class="ds-thread" data-thread-key="{{ page.path }}"
              data-title="{{ page.title }}" data-url="{{ page.permalink }}">
         </div>
       {% elseif theme.facebook_sdk.enable and theme.facebook_comments_plugin.enable %}
         <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>
       {% elseif theme.disqus_shortname %}
         <div id="disqus_thread">
           <noscript>
             Please enable JavaScript to view the
             <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a>
           </noscript>
         </div>
       {% elseif theme.hypercomments_id %}
         <div id="hypercomments_widget"></div>
       {% elseif theme.gentie_productKey %}
         <div id="cloud-tie-wrapper" class="cloud-tie-wrapper"></div>
       {% elseif theme.youyan_uid %}
            <div id="uyan_frame"></div>
       {% endif %}
     </div>
   {% endif %}

(4). 在thems/next/_config.ymlThird Party Services Settings下添加友言的配置信息。

# ---------------------------------------------------------------
# Third Party Services Settings
# ---------------------------------------------------------------

# Duoshuo ShortName
#duoshuo_shortname:

# youyan
youyan_uid: 你的UID

至此,改造完成。运行hexo clean清理一下目录,hexo g重新生成一次所有的文档,hexo s运行服务器以后,就可以查看评论效果了,效果如下图:

更多精彩文章,请访问我的博客http://jinfang.life

相关文章

网友评论

  • 5ec1da87f063:现在支持https了么?
  • 松n_n鼠: 博主,我这里按照你的配置的,但是评论就是出不来,不知道为什么,部署的时候也没有错误提示。
    laughing_club:友言不支持https请求,我的GitHub pages是https 的,所以本地没问题,部署就有问题了,我估计是这个原因
    chenkchen:@Hell0_C 你看一下你的repo地址有没问题
    Hell0_C:我的也一样,你解决了吗
  • DSperson:http://www.dsperson.com/2017/06/14/lldb%E5%AD%A6%E4%B9%A0/ 帅哥你帮我看看 我哪里搞错了 怎么两个评论框...O(∩_∩)O谢谢
  • boxcore:不错,可惜友言不支持https啊,这个是大问题!
    Einskang:对啊,今下午有时间就把不提供服务了的多说换成了友言,但是却不支持 https 请求,真是爆炸……
  • thinkgamer:你好,我在用你这个方法的时候,遇到一个问题提示:抱歉,当前网页参数有误,操作失败
    看调试窗口是:
    VM1242:1 A Parser-blocking, cross site (i.e. different eTLD+1) script, http://v3.jiathis.com/code/plugin.client.js, is invoked via document.write. This MAY be blocked by the browser in this or a future page load due to poor network connectivity. If blocked in this page load, it will be confirmed in a subsequent console message.See https://www.chromestatus.com/feature/5718547946799104 for more details.
    你知道怎么回事吗
    思_路:这个应该是友言的问题。
  • 2979e8f9fa2e:博主你好懒啊,这个<!--more-->明显实从hexo上的MD拷过来的,哈哈哈:smirk:
    思_路:哈哈,不好意思,忘记删了。:smile:
  • Jacok:博主你的next目录结构跟我的不一样 添加的id起作用 能加我帮我看看么? QQ721931156
    ania:我也是也是目录不一样,没有third_party这个目录,怎么处理的?
    那仅有的执著:我也是,目录不一样,你解决了吗?
  • 思_路:hexo之next主题第三方评论系统(http://jinfang.life/posts/989a1501/)
  • 1f8cded35a43:刚好遇到同样问题,结果就看到这篇文章,必须给个赞

本文标题:为next添加友言评论支持

本文链接:https://www.haomeiwen.com/subject/exwevttx.html