注册LeanCloud
打开其官网点击快速开始,
嗯,需要注册LeanCloud,注册如下
验证邮箱和绑定手机号
然后点击创建应用>开发版
建好之后点击进入到应用中
依次点击设置>应用Key得到AppID和AppKey
设置安全域名,可设可不设咯。设得话要设自己博客域名哦(不要设博主的哦)
注册好了,去valine官网找到demo
在 _config.yml 中添加
#6、Valine https://valine.js.org
valine:
appid: #Leancloud应用的appId
appkey: #Leancloud应用的appKey
verify: false #验证码
notify: false #评论回复提醒
avatar: mm #评论列表头像样式:''/mm/identicon/monsterid/wavatar/retro/hide
placeholder: Just go go #评论框占位符
在 layout/_partial/article.ejs 中添加
<% if (theme.valine && theme.valine.appid && theme.valine.appkey){ %>
<section id="comments" style="margin:10px;padding:10px;background:#fff;">
<%- partial('post/valine', {
key: post.slug,
title: post.title,
url: config.url+url_for(post.path)
}) %>
</section>
<% } %>
新建文件layout/_partial/post/valine.ejs
<div id="vcomment" class="comment"></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>
var notify = '<%= theme.valine.notify %>' == true ? true : false;
var verify = '<%= theme.valine.verify %>' == true ? true : false;
window.onload = function() {
new Valine({
el: '.comment',
notify: notify,
verify: verify,
app_id: "<%= theme.valine.appid %>",
app_key: "<%= theme.valine.appkey %>",
placeholder: "<%= theme.valine.placeholder %>",
avatar:"<%= theme.valine.avatar %>"
});
}
</script>
至此,大功告成
article.ejs 代码添加到 <% if (!index && post.comments){ %> 下面