爲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

相關文章
相關標籤/搜索