title: 將hexo的評論系統由gitment改為Valine
toc: false
date: 2018-09-13 15:10:56
categories:
- methods
tags:
- hexo
- gitment
- Valine
首先注冊LeanCloud,注冊后添加應用,然后選擇應用>設置>應用key
就可以看到自己的AppID和AppKey了。
然后進入自己的主題目錄(比如我的主題是默認的landscape
):
刪除配置gitment時/themes/landscape/layout/_partial/post
目錄下添加的git.ejs
文件,
然后編輯/themes/landscape/layout/_partial/
目錄下的article.ejs
,將原本配置gitment時添加在最后的那段代碼刪掉,添加:
<% if (!index){ %>
<% if (post.comments){ %>
<div id="vcomments"></div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='//unpkg.com/valine/dist/Valine.min.js'></script>
<script>
new Valine({
el: '#vcomments',
appId: '你的appid',
appKey: '你的appkey',
notify:true,
verify:true,
visitor:true,
avatar:'mm',
placeholder: '嘻嘻嘻'
})
</script>
<% } else { %>
<div class="vcomments"></div>
<% } %>
<% } %>
其中notify為郵件提醒功能是否開啟,verify為驗證碼功能,visitor為文章訪問量統計功能,avatar為Gravatar
頭像展示方式。
在leancloud的應用>設置>安全中心>Web安全域名
中添加你的域名。
然后就OK啦!!
有其他問題可以訪問Valine官方文檔查看。
關於出現Code 403: 訪問被api域名白名單拒絕,請檢查你的安全域名設置.
的問題:
我的問題是同時在github和coding上部署了,但是在leancloud的應用>設置>安全中心>Web安全域名
中只添加了github的域名,因此在coding的那個域名訪問時就會出現上述問題,添加域名即可解決問題。