hexo(四)轻松整合统计模块

hexo在yelee主题下搭建统计模块

1.安装 hexo-wordcount

在博客目录下打开Git Bash Here 输入命令

npm i –save hexo-wordcount

2.文件配置
在theme\yilia\layout_partial\post下创建word.ejs文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<div style="margin-top:10px;">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-keyboard-o"></i>
<span class="post-meta-item-text"> 字数统计: </span>
<span class="post-count"><%= wordcount(post.content) %>字</span>
</span>
</span>

<span class="post-time">
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
<i class="fa fa-hourglass-half"></i>
<span class="post-meta-item-text"> 阅读时长: </span>
<span class="post-count"><%= min2read(post.content) %>分</span>
</span>
</span>
</div>

3.然后在 themes/yilia/layout/_partial/article.ejs中添加

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<div class="article-inner">
<% if (post.link || post.title){ %>
<header class="article-header">
<%- partial('post/title', {class_name: 'article-title'}) %>
<% if (!post.noDate){ %>
<%- partial('post/date', {class_name: 'archive-article-date', date_format: null}) %>
<!-- 需要添加的位置 -->
<!-- 开始添加字数统计-->
<% if(theme.word_count && !post.no_word_count){%>
<%- partial('post/word') %>
<% } %>
<!-- 添加完成 -->

<% } %>
</header>

**注意:
很多人做到上面两步,却发现页面并没有效果是因为没有开启功能

只要在站点的_config.yml中添加下面代码

是否开启字数统计

不需要使用,直接设置值为false或注释掉
word_count: True