Cactus博客添加字数统计

  |  

一、安装

1
2
3
yarn add hexo-wordcount
# or
npm i --save hexo-wordcount

二、使用

新建Word.ejs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!-- # 添加文件:themes/cactus/layout/_partial/post/word.ejs -->
<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(page.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(page.content) %>分</span>
</span>
</span>
</div>

修改Post.ejs文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<header>
<%- partial('_partial/post/title', { post: page, index: false, class_name: 'posttitle' }) %>
<div class="meta">
<span class="author p-author h-card" itemprop="author" itemscope itemtype="http://schema.org/Person">
<span class="p-name" itemprop="name"><% if (page.author) { %><%- page.author %><% } else { %><%- config.author %><% } %></span>
</span>
<%- partial('_partial/post/date', { post: page, class_name: 'postdate' }) %>
<%- partial('_partial/post/category') %>
<%- partial('_partial/post/tag') %>
<!-- 字数统计 -->
<% if (theme.word_count && !page.no_word_count) { %>
<%- partial('_partial/post/word') %>
<% } %>
</div>
</header>

修改_config.yml文件

1
2
3
# 是否开启字数统计
#不需要使用,直接设置值为false,或注释掉
word_count: true

三、完结撒花

字数统计

本文作者: Seyou
发布时间: 2024-03-22
最后更新: 2024-03-23
本文标题: Cactus博客添加字数统计
本文链接: https://seyou.lol/posts/2024/03/5ba8452a.html
版权声明: 本作品采用 CC BY-NC-ND 4.0 许可协议进行许可。转载请注明出处!