1. 使用多说评论
  2. 对于hexo用户

网站的评论功能使用多说( http://duoshuo.com/ )。

考虑到Disqus在国内基本访问不到,所以还是把评论功能换成国内能访问的较常用的多说(duoshuo)(使用微信、微博、QQ、人人、豆瓣、开心、百度、谷歌的账号登录)吧。

此外Comm(ent|it)( https://commentit.io/ )似乎也是个不错的选择(使用github, facebook, twitter账号登录),但对hexo开发者来说可能不太适用。

使用多说评论

注册账号,然后填入网站相关内容,之后会提示把以下代码复制并粘帖到您网页代码<body></body>间的任意位置。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!-- 多说评论框 start -->
<div class="ds-thread" data-thread-key="请将此处替换成文章在你的站点中的ID" data-title="请替换成文章的标题" data-url="请替换成文章的网址"></div>
<!-- 多说评论框 end -->
<!-- 多说公共JS代码 start (一个网页只需插入一次) -->
<script type="text/javascript">
var duoshuoQuery = {short_name:"你的多说short_name"};
(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 -->

对于hexo用户

对hexo用户,可以使用以下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!-- 多说评论框 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:"<%= 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>
<!-- 多说公共JS代码 end -->

对tranquilpeak主题来说,可作如下修改:

  • /themes/tranquilpeak/layout/_partial/script.ejs中加入

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    <% if (theme.duoshuo_shortname && is_post() && post.comments) { %>
    <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>
    <% } %>

  • 修改themes/tranquilpeak/layout/_partial/post.ejs

    1
    2
    3
    4
    5
    6
    <div class="post-footer main-content-wrap">
    <%- partial('post/actions') %>
    <% if (post.comments && theme.duoshuo_shortname) { %>
    <%- partial('post/duoshuo') %>
    <% } %>
    </div>

  • 修改themes/tranquilpeak/layout/_partial/post/actions.ejs

    1
    <a class="post-action-btn btn btn--default" href="#ds-thread">

  • themes/tranquilpeak/_config.yml中加入

    1
    duoshuo_shortname: 你的多说shortname

  • 添加themes/tranquilpeak/layout/_partial/post/duoshuo.ejs

    1
    2
    <div class="ds-thread" data-thread-key="<%= post.layout %>-<%= post.slug %>" data-title="<%= post.title %>" data-url="<%= page.permalink %>">
    </div>