为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.

3. 修改评论模块代码:

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

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即可看到文章下方出现的评论模块.

lemostic.github.io

 

转载于:https://www.cnblogs.com/Lemostic/p/5493407.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值