Gavin Zhou
Back to Writing

Hexo配置多说评论详细教程

由于hexo默认评论插件为Disqus,仅支持G+、twitter等登陆,不符合我国国情。因此为了方便国内使用,选择多说来代替Dispus。

1.添加多说配置

在_config.yml(注意在根目录,不是主题文件夹)中增加

duoshuo_shortname: 你站点的short_name

看了网上很多同学都不明白此处的short_name是什么,其实你需要先在多说官网创建一个站点,用于管理你的评论。地址如下:

创建多说站点地址

short_name 就是上面填多说域名中example.duoshuo.com里的example

2.修改模板

如果使用的是默认模板,修改themes\landscape\layout\_partial\article.ejs模板

如果是其他主题,请修改themes\主题\layout\_partial\comment.ejs模板

把

<% if (!index && post.comments && config.disqus_shortname){ %>
  <section id="comments">
    <div id="disqus_thread">
      <noscript>Please enable JavaScript to view the <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    </div>
  </section>
<% } %>

改为

  <% if (!index && post.comments && config.duoshuo_shortname){ %>
  <section id="comments">
    <!-- 多说评论框 start -->
    <div class="ds-thread" data-thread-key="<%= post.layout %>-<%= post.slug %>" data-title="<%= post.title %>" data-url="<%= page.permalink %>"></div>
    <!-- 多说评论框 end -->
    <!-- 多说公共JS代码 start (一个网页只需插入一次) -->
    <script type="text/javascript">
    var duoshuoQuery = {short_name:'<%= config.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>
    <!-- 多说公共JS代码 end -->
  </section>
  <% } %>

Over

Comments