Giter Site home page Giter Site logo

hexo-wordcount's Introduction

Hexo-WordCount

npm npm npm

Installation

yarn add hexo-wordcount
# or
npm i --save hexo-wordcount

Usage

字数统计 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)

Demo

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) }}</span>

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)

LICENSE

MIT

Alipay Donation(通过支付宝捐赠):

qr

hexo-wordcount's People

Contributors

gasolin avatar willin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hexo-wordcount's Issues

Bug with Arabic language.

  1. Go on test post.
  2. See Words count in article: 10 in meta. There are more then 10 words in this article, i think.
  3. See other articles on this site — other posts in normal counting state.

So, bug with RTL language counting.

hexo g error

TypeError: (intermediate value)(intermediate value)(intermediate value)(...).replace is not a function
at Object._ctx.post_template.render (eval at precompile (/xxx/node_modules/swig-templates/lib/swig.js:537:13), :186:950)
at Object.eval [as tpl] (eval at precompile (/xxx/node_modules/swig-templates/lib/swig.js:537:13), :774:1078)


可能是某篇文章有问题(因为都删掉,只留某一篇文章,就没问题),但是文章太多了.....

这个报错能发现什么问题吗?

I have installed hexo-wordcount,but I've got a problem with hexo-g

我已经装好了,word.ejs也配置好了,但是generate的时候就显示post not defined
以下是报错信息:

ERROR D:\王楚屹\Hexo\jerrywcy.github.io\themes\alpha-dust\layout\post.ejs:15
    13|         </span>
    14|         <section class="main">
 >> 15|             <%- partial('_partial/article-long', {item: page}) %>
    16|         </section>
    17|
    18|     </div>

D:\王楚屹\Hexo\jerrywcy.github.io\themes\alpha-dust\layout\_partial\article-long.ejs:28
    26|         <!-- hexo-wordcount -->
    27|         <% if(true){ %>
 >> 28|             <%- partial('word') %>
    29|         <% } %>
    30|         <!-- Gallery -->
    31|         <% if (item.photos && item.photos.length){ %>

D:\王楚屹\Hexo\jerrywcy.github.io\themes\alpha-dust\layout\_partial\word.ejs:6
    4|         <i class="fa fa-keyboard-o"></i>
    5|         <span class="post-meta-item-text">  字数统计: </span>
 >> 6|         <span class="post-count"><%= wordcount(post.content) %>字</span>
    7|       </span>
    8|     </span>
    9|

post is not defined
ReferenceError: D:\王楚屹\Hexo\jerrywcy.github.io\themes\alpha-dust\layout\post.ejs:15
    13|         </span>
    14|         <section class="main">
 >> 15|             <%- partial('_partial/article-long', {item: page}) %>
    16|         </section>
    17|
    18|     </div>

D:\王楚屹\Hexo\jerrywcy.github.io\themes\alpha-dust\layout\_partial\article-long.ejs:28
    26|         <!-- hexo-wordcount -->
    27|         <% if(true){ %>
 >> 28|             <%- partial('word') %>
    29|         <% } %>
    30|         <!-- Gallery -->
    31|         <% if (item.photos && item.photos.length){ %>

D:\王楚屹\Hexo\jerrywcy.github.io\themes\alpha-dust\layout\_partial\word.ejs:6
    4|         <i class="fa fa-keyboard-o"></i>
    5|         <span class="post-meta-item-text">  字数统计: </span>
 >> 6|         <span class="post-count"><%= wordcount(post.content) %>字</span>
    7|       </span>
    8|     </span>
    9|

post is not defined
    at eval (eval at compile (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\ejs\lib\ejs.js:633:12), <anonymous>:11:36)
    at returnedFn (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\ejs\lib\ejs.js:668:17)
    at Object.exports.render (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\ejs\lib\ejs.js:419:37)
    at Hexo.ejsRenderer (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\hexo-renderer-ejs\lib\renderer.js:7:14)
    at Render.renderSync (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\hexo\lib\hexo\render.js:96:22)
    at Theme._View.View._compiledSync (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\hexo\lib\theme\view.js:126:43)
    at Theme._View.View.View.renderSync (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\hexo\lib\theme\view.js:48:23)
    at Object.partial (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\hexo\lib\plugins\helper\partial.js:34:15)
    at eval (eval at compile (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\ejs\lib\ejs.js:633:12), <anonymous>:49:17)
    at returnedFn (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\ejs\lib\ejs.js:668:17)
    at Object.exports.render (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\ejs\lib\ejs.js:419:37)
    at Hexo.ejsRenderer (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\hexo-renderer-ejs\lib\renderer.js:7:14)
    at Render.renderSync (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\hexo\lib\hexo\render.js:96:22)
    at Theme._View.View._compiledSync (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\hexo\lib\theme\view.js:126:43)
    at Theme._View.View.View.renderSync (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\hexo\lib\theme\view.js:48:23)
    at Object.partial (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\hexo\lib\plugins\helper\partial.js:34:15)
    at eval (eval at exports.compile (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\hexo-renderer-mathjax\node_modules\ejs\lib\ejs.js:242:14), <anonymous>:30:707)
    at eval (eval at exports.compile (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\hexo-renderer-mathjax\node_modules\ejs\lib\ejs.js:242:14), <anonymous>:30:808)
    at D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\hexo-renderer-mathjax\node_modules\ejs\lib\ejs.js:255:15
    at Object.exports.render (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\hexo-renderer-mathjax\node_modules\ejs\lib\ejs.js:293:13)
    at Hexo.<anonymous> (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\hexo-renderer-mathjax\index.js:14:24)
    at Hexo.tryCatcher (D:\王楚屹\Hexo\jerrywcy.github.io\node_modules\bluebird\js\release\util.js:16:23)

但是我页面底部的全站字数统计是正常的
一加上这个整个文章页面就都空白了。

<html>
        <head></head>
        <body></body>
</html>

所有文章的html文件都长这样
大佬帮帮忙!

Issue with 'use strict'

When use with theme Next, texting the site locally by using hexo s, it gives the error as follows:

ERROR Plugin load failed: hexo-wordcount
/path/to/hexo/site/node_modules/hexo-wordcount/index.js:17
  'use strict';
  ^^^^^^^^^^^^

SyntaxError: Illegal 'use strict' directive in function with non-simple parameter list
    at createScript (vm.js:74:10)
    at Object.runInThisContext (vm.js:116:10)
...

And none of word count and time to read is working.

Bug Report -

return numeral(
    content.match(/[\u4E00-\u9FA5]/g).length + //中文
    content.match(/(\W*\w*\W)/g).length  //英文
).format('0,0');

在index.js文件中,以上代码在new一个空博文后,hexo g时会报错,没有length

The html-to-text causes performance issue

Thanks for this great plugin.

Recently we found it causes some performance issue. We have a website with around 200 posts, normally it takes 1 mins to generate, however, after installed the hexo-wordcount, it needs more than 7 mins to generate.

After run nodejs profiler and analysis the result, we figure out one package in node causing the issue, it is the html-to-text, and it is the wordcount dependency. So we tried to remove the hexo-wordcount, the issue resolved.

Could you please take a look at this? Please let me know if you need more information.

Load Failed

Using:

  • hexo: 3.3.8
  • hexo-cli: 1.0.3
  • os: Linux 4.10.0-32-generic linux x64
  • http_parser: 2.7.0
  • node: 4.7.2
  • v8: 4.5.103.43
  • uv: 1.9.1
  • zlib: 1.2.8
  • ares: 1.10.1-DEV
  • icu: 57.1
  • modules: 46
  • openssl: 1.0.2g

Theme: next

Output:

➜  content node_modules/hexo/bin/hexo g
ERROR Plugin load failed: hexo-wordcount
SyntaxError: Unexpected token {
    at Object.exports.runInThisContext (vm.js:53:16)
    at /home/hwding/Work/blog/content/node_modules/hexo/lib/hexo/index.js:230:17
    at tryCatcher (/home/hwding/Work/blog/content/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/hwding/Work/blog/content/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/home/hwding/Work/blog/content/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/home/hwding/Work/blog/content/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/home/hwding/Work/blog/content/node_modules/bluebird/js/release/promise.js:693:18)
    at Promise._fulfill (/home/hwding/Work/blog/content/node_modules/bluebird/js/release/promise.js:638:18)
    at Promise._resolveCallback (/home/hwding/Work/blog/content/node_modules/bluebird/js/release/promise.js:432:57)
    at Promise._settlePromiseFromHandler (/home/hwding/Work/blog/content/node_modules/bluebird/js/release/promise.js:524:17)
    at Promise._settlePromise (/home/hwding/Work/blog/content/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/home/hwding/Work/blog/content/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/home/hwding/Work/blog/content/node_modules/bluebird/js/release/promise.js:693:18)
    at Promise._fulfill (/home/hwding/Work/blog/content/node_modules/bluebird/js/release/promise.js:638:18)
    at /home/hwding/Work/blog/content/node_modules/bluebird/js/release/nodeback.js:42:21
    at /home/hwding/Work/blog/content/node_modules/graceful-fs/graceful-fs.js:78:16
INFO  Start processing
INFO  Files loaded in 593 ms
INFO  0 files generated in 691 ms

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.