如需转载,请根据 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 许可,附上本文作者及链接。
本文作者: 执笔成念
作者昵称: zbcn
本文链接: https://1363653611.github.io/zbcn.github.io/2020/05/10/hexo_03comment/
最近打算给博客添加评论功能,看了下市面上一些评论插件,觉得gitment和Valine这两款插件比较符合我的要求:轻量而且配置简单。
不过gitment只支持github账号评论,虽然也没啥人看我博客,不过权衡了下,还是决定用Valine。
我hexo博客主题用的是yilia,看了下_config.yml配置文件,发现它竟默认支持gitment,为了也能使用valine,只能魔改源码了。
- 修改yilia主题下的_config.yml文件,添加valine配置
1
# valine配置
2
valine_appid: '填写leancloud的appid'
3
valine_appkey: '填写leancloud的appkey'
- 修改layout/_partial/article.ejs,添加一段代码
1
<% if (!index){ %>
2
<% if (theme.valine && theme.valine.appid && theme.valine.appkey){ %>
3
<section id="comments" class="comments">
4
<style>
5
.comments{margin:30px;padding:10px;background:#fff}
6
@media screen and (max-width:800px){.comments{margin:auto;padding:10px;background:#fff}}
7
</style>
8
<%- partial('post/valine', {
9
key: post.slug,
10
title: post.title,
11
url: config.url+url_for(post.path)
12
}) %>
13
</section>
14
<% } %>
15
<% } %>
- 新增 layout/_partial/post/valine.ejs
1
<div id="comment"></div>
2
<script src='//unpkg.com/valine/dist/Valine.min.js'></script>
3
<script>
4
new Valine({
5
el: '#comment' ,
6
notify:false,
7
verify:false,
8
appId: '<%=theme.valine_appid%>',
9
appKey: '<%=theme.valine_appkey%>',
10
placeholder: 'ヾノ≧∀≦)o欢迎评论!',
11
path:window.location.pathname,
12
avatar:'mm'
13
});
14
</script>
大功搞成了.