如何利用Hexo在自己的博客中添加多说评论

利用github+hexo搭建自己的博客后,可以自定义搭建自己的博客,要为自己的博客添加留言功能,需要完成一下几部:

#一、注册自己的多说账号
在百度上搜索多说,创建自己的站点,得到一个多说的二级域名。

#二、修改自己本地的配置文件
在自己的博客根目录下以文本编辑器打开_config.yml文件,添加duoshuo_shortname: 你在多说得到的二级域名。当然也可以在根目录下找到themes文件夹,选中你用的主题的配置文件_config.yml文件,将其中的duoshuo_shortname:的值赋为多说二级域名。

接下来需要修改选用主题的部分js脚本内容,如果你使用的是默认的landscape主题,这时只需要修改:你的博客根目录\themes\landscape\layout_partial\article.ejs中的以下代码

1
2
3
4
5
6
7
<% 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>
<% } %>

改为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<% if (!index && post.comments && config.duoshuo_shortname){ %>
<section id="comments">
<div id="ds-thread" class="ds-thread" data-thread-key="<%= post.path %>" data-title="<%= post.title %>" data-url="<%= post.permalink %>"></div>
<script type="text/javascript">
var duoshuoQuery = {short_name:"datoublog"};
(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>
</section>
<% } %>

如果你使用的自定义主题,比如我使用的cyanstyle,需要直接在\themes\cyanstyle\layout_partial中article.ejs添加上面的部分代码。

1