为hexo博客支持Valine评论的主题cactus增加文章浏览量功能
增加主题浏览量配置
找到_config.yml
(位于主题根目录)valine
配置块中增加visitor: true
选项
完整内容如下:
# Fill in your valine Comments Params to enable valine comments.
valine:
enabled: true
appId: 0qst44fQiSldyB6P4rirrzrA-gzGzoHsz
appKey: BFsvmHRt2YaSY7goohpimImw
notify: false
verify: false
avatar: 'mm'
placeholder: 'just go go'
visitor: true
在文章模板中增加代码块
找到post.ejs
(位于主题layout
)配置文件,按下图所示增加代码块
<% if (theme.valine.enabled && theme.valine.appId && theme.valine.appKey && theme.valine.visitor){ %>
<%- partial('_partial/post/visitors', { post: page, class_name: 'leancloud-visitors' }) %>
<% } %>
新建visitors.ejs文件
在主题layout/_partial/post
目录下新建visitors.ejs
作为实际的功能代码文件,在其中输入下面的代码串
<span id="<%- url_for(post.path) %>" class="<%= class_name %>" data-flag-title="<%= post.title %>">
<em class="post-meta-item-text">阅读量 </em>
<i class="leancloud-visitors-count">0</i>
</span>
结束
最后全部保存并从新生成,现在去测试一下文章能否访问计数了吧。
如图所展示的:
表示能正常工作了。