为Hexo博客添加评论模块

1. 登陆多说网站http://duoshuo.com/,建立站点:

1
2
3
能够使用经常使用的社交帐号进行登陆,无需注册
选择`我要安装`来建立一个站点
录入基本的建立信息,点击`建立`按钮来建立一个站点

2. 修改主题配置文件:

我用的主题是freemind,主题地址https://github.com/wzpan/hexo-theme-freemind.git,修改主题的步骤请参考”修改Hexo博客主题”
1.打开当前主题路径/_config.yml,找到duoshuo_shortname标签,设置为刚才建立站点时多说域名中的内容,请注意,没有前缀http://和后缀.duoshuo.com.javascript

3. 修改评论模块代码:

打开文件Hexo\themes\freemind\layout\_partial\post\comment.ejs,将原有代码替换为以下代码:
java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<% if (page.comment){ %>
<section id="comment">
<h2 class="title"><%= __('comment') %></h2>

<% if(theme.duoshuo_shortname) { %>

<!-- 多说评论框 start -->
<div class="ds-thread" data-thread-key="<%- page.path %>" data-title="<%- page.title %>" data-url="<%- page.permalink %>"></div>
<!-- 多说评论框 end -->
<!-- 多说公共JS代码 start (一个网页只需插入一次) -->
<script type="text/javascript">
var duoshuoQuery = {short_name:"duoshuo_shortname"}; <!-- 替换这里的duoshuo_shortname为前面注册的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.unstable.js';
ds.charset = 'UTF-8';
(document.getElementsByTagName('head')[0]
|| document.getElementsByTagName('body')[0]).appendChild(ds);
})();
</script>
<!-- 多说公共JS代码 end -->

<% } else if(config.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>
<% } %>

</section>
<% } %>

部署到github便可看到文章下方出现的评论模块.git

lemostic.github.iogithub

相关文章
相关标签/搜索