1. themes\ocean\layout\_partial路径下创建文件word-count.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"> words count: </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"> expected cost: </span>
<span class="post-count"><%= min2read(post.content) >1 ? min2read(post.content)+" minutes" : min2read(post.content)+" minute"%> </span>
</span>
</span>
</div>

2. 在themes\ocean\layout\_partial\article.ejs中添加以下代码

1
2
3
4
5
<!-- 开始添加字数统计-->
<% if(theme.word_count ){%>
<%- partial('word-count') %>
<% } %>
<!-- 结束 -->
  • 具体位置是在article-inner的div中的header中,例如我的位置是

3. 在主题配置文件themes\ocean\_config.yml中添加

1
word_count: true

4. hexo clean & hexo g & hexo s

5. 总结:

  • 创建一个ejs用来渲染前端显示的具体内容
  • 设定ejs作用位置
  • 创建一个变量选择是否开启此功能

    纯前端小白简单理解,期望与各路大佬多多交流




网络上都是以next的配置为主,但next很多是主题作者预先放置好的,所以作者找到了这篇为yilia添加此功能的,做了微小改动。
参考 https://chocolate.blog.csdn.net/article/details/104262008