為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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM