安装
yarn add hexo-wordcount
# or
npm i --save hexo-wordcount
# Node 版本7.6.0之前,请安装 2.x 版本 (Node.js v7.6.0 and previous)
npm install hexo-wordcount@2 --save
用法
字数统计WordCount
wordcount(post.content)
阅读时长预计Min2Read
min2read(post.content)
设置阅读速度 Set Reading Speed:
min2read(post.content, {cn: 300, en: 160})
// p.s. (v3.0.0 added)
总字数统计TotalCount
totalcount(site, '0,0.0a')
第二个参数为可选参数,表示字数显示的 format,文档参考:http://numeraljs.com/
演示
Swig
Post Count:
<span class="post-count">{{ wordcount(post.content) }}</span>
Post Minutes to Read:
<span class="post-count">{{ min2read(post.content) }}</span>
Total Count:
<span class="post-count">{{ totalcount(site, '0,0.0a') }}</span>
第二个参数format可选。
Ejs
Post Count:
<span class="post-count"><%= wordcount(post.content) %></span>
Post Minutes to Read:
<span class="post-count"><%= min2read(post.content) %></span>
Total Count:
<span class="post-count"><%= totalcount(site) %></span>
Jade
Post Count:
span.post-count= wordcount(post.content)
Post Minutes to Read:
span.post-count= min2read(post.content)
Total Count:
span.post-count= totalcount(site)