LI YAO'S BLOG

有趣的人生, 一半家长里短, 一半山川胡海

Hexo文章添加字数统计功能

1.首先在博客目录下使用npm安装插件:

1
npm install hexo-wordcount

2.在主题配置文件_config.yml中增加配置:

1
2
# 开启字数统计
word_count: true

3.检查配置中是否symbols_count_time项,没有的话加上

1
2
3
4
5
6
# Post wordcount display settings
# Dependencies: https://github.com/theme-next/hexo-symbols-count-time
symbols_count_time:
separated_meta: false //是否与常规post-meta条目换行
item_text_post: true
item_text_total: true

4.如果需要在页面底部网站信息处也加上字数统计需要修改footer.swig文件信息

文件路径:...\themes\next\layout\_partials\footer.swig

在文件的最后添加如下内容:

1
2
3
4
<div class=“theme-info”>
<div class=“powered-by”></div>
<span class=“post-count”>共{{ totalcount(site) }}字</span>
</div>

配置好后,使用hexo g与hexo s命令部署启动查看效果即可

赞赏一杯咖啡