💡 参考文章见Ref,感谢提供思路!
🗺️当前这篇博文地址:https://myoontyee.github.io/article/11459889.html
⚠️警告:博客文章禁止一切形式的非授权非法转载!
⚠️Attention: All forms of unauthorized illegal reposts are prohibited !

创建时间:2022年3月30日19:59:04
最新更新:2022年3月30日19:59:09


核心思路

  • 部署hexo-wordcount

  • 主题下的_config.yml配置

  • 主题下的post页面配置


  • 最终效果如下图

部署插件

  • 文章字数和阅读时长的统计都是借助 hexo-wordcount 插件实现,可以使用 npm安装
1
2
3

npm i --save hexo-wordcount

  • Node 版本在 7.6.0 之前,需要安装 2.x 版本
    • 查看Node版本,需要在Git-Bash内输入Node -v即可查看
    • 安装2.x版本,需要在Git-Bash内输入npm i --save hexo-wordcount@2

配置文件

  • 编译器(如Visual Stuidio Code)打开themes\Chic\_config.yml,添加如下内容
    • 注意2个_enable开关,即post_wordcount_enablepost_min2read_enable不能放在post_wordcount:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

# 文章字数和阅读时长

# Post wordcount display settings

# Dependencies: https://github.com/willin/hexo-wordcount

post_wordcount:

item_text: true

wordcount: true # 单篇 字数统计

min2read: true # 单篇 阅读时长

totalcount: false # 网站 字数统计



post_wordcount_enable: true # 字数统计

post_min2read_enable: true # 阅读时长

post页面配置

  • 编译器打开themes\Chic\layout\_page\post.ejs,按如下方式添加修改内容,在下图位置替换对应内容

修改前

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

<% if(page.categories.length!==0 && theme.post_category_enable){ %>

<span class="post-category">

Category:

<% page.categories.forEach(item=>{ %>

<a href="<%- url_for(item.path) %>"><%- item.name %></a>

<% }) %>

</span>

<% } %>

修改后

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

<% if(page.categories.length!==0 && theme.post_category_enable){ %>

<span class="post-category">

Category:

<% page.categories.forEach(item=>{ %>

<a href="<%- url_for(item.path) %>"><%- item.name %></a>

<% }) %>

</span>

<% } %>



<% if(page.content && theme.post_wordcount_enable){ %>

<span class="post-count">

Words:

<a href=""><%= wordcount(page.content) %></a>

</span>

<% } %>



<% if(page.content && theme.post_min2read_enable){ %>

<span class="post-count">

Time:

<a href=""><%= min2read(post.content) %>min</a>

</span>

<% } %>

Ref