Skip to content

Commit

Permalink
0.4.0
Browse files Browse the repository at this point in the history
1. Modified default settings: AWL = 4; WPM = 275.
2. Added suffix as string parameter if time to read less then 60 minutes. Default: 'mins.' (#11).
3. Updated readme.
  • Loading branch information
ivan-nginx committed Apr 14, 2018
1 parent 05a9f8c commit dadc4cc
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 122 deletions.
158 changes: 60 additions & 98 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@

Symbols count and time to read of articles.

Better then `hexo-reading-time` and faster then `hexo-worcount`. No dependencies.
Better than [`hexo-reading-time`](https://github.com/ierhyna/hexo-reading-time) and faster than [`hexo-worcount`](https://github.com/willin/hexo-wordcount). No external dependencies.

## Installation

[![size-image]](../../blob/master/lib/helper.js) <!--[![rel-image]](../../releases)-->
[![dm-image]][npm-url]
[![dt-image]][npm-url]
Expand All @@ -53,148 +54,109 @@ npm install hexo-symbols-count-time --save
```

## Usage
Activate this plugin in hexo's `_config.yml` (which locates in the root dir of your blog) by enabled any option:

Activate this plugin in **hexo's `_config.yml`** (which locates in the root dir of your blog) by enabled any option:

```yml
symbols_count_time:
symbols: true
time: true
total_symbols: true
total_time: true
```
If `symbols_count_time` not specified (or commented), plugin will totally disabled.

### NexT theme
This plugin integrated in «NexT» and after plugin enabled in main Hexo config, need to enable options in NexT config:

This plugin integrated in «NexT» and after plugin enabled in main Hexo config, you may adjust options in NexT config:

```yml
symbols_count_time:
separated_meta: true
item_text_post: true
item_text_total: false
awl: 5
wpm: 200
awl: 4
wpm: 275
```

### Other themes
#### Parameters

#### Swig
* `AWL` — Average Word Length (chars count in word). Default: `4`. You can check this [here](https://charactercounttool.com).
* CN &asymp; `2`
* EN &asymp; `5`
* RU &asymp; `6`
* `WPM` — Words Per Minute. Default: `275`. You can check this [here](https://wordcounter.net).
* Slow &asymp; `200`
* Normal &asymp; `275`
* Fast &asymp; `350`
* `Suffix` — If time to read less then 60 minutes, added suffix as string parameter. Default: `mins.`

##### Symbols Count
```js
{{ symbolsCount(post.content) }}
```
**Note for Chinese users:** because in Chinese language average word length about `~1.5` and if you at most cases write posts in Chinese (without mixed English), recommended to set `awl` to `2` and `wpm` to `300`.\
But if you usualy mix your posts with English, `awl` to `4` and `wpm` to `275` will be nice.

##### Symbols Time
```js
{{ symbolsTime(post.content) }}
```
OR
```js
{{ symbolsTime(post.content, AWL, WPM) }}
```
## Development

##### Symbols Count Total
```js
{{ symbolsCountTotal(site) }}
```bash
cd hexo
git clone https://github.com/theme-next/hexo-symbols-count-time.git node_modules/hexo-symbols-count-time
cd node_modules/hexo-symbols-count-time
```

##### Symbols Time Total
```js
{{ symbolsTimeTotal(site) }}
```
OR
```js
{{ symbolsTimeTotal(site, AWL, WPM) }}
### Tests

```bash
npm install mocha chai --save-dev
npm test
```

#### EJS
### Tests with coverage

##### Symbols Count
```ejs
<%- symbolsCount(post.content) %>
```bash
npm install -g istanbul
istanbul cover --print both node_modules/.bin/_mocha -- test/index.js
```

##### Symbols Time
```ejs
<%- symbolsTime(post.content) %>
```
OR
```ejs
<%- symbolsTime(post.content, AWL, WPM) %>
```
### Templates

##### Symbols Count Total
```ejs
<%- symbolsCountTotal(site) %>
```
#### Symbols Count

##### Symbols Time Total
```ejs
<%- symbolsTimeTotal(site) %>
```
OR
```ejs
<%- symbolsTimeTotal(site, AWL, WPM) %>
```js
{{ symbolsCount(post.content) }}
```

#### Jade
#### Symbols Time

##### Symbols Count
```jade
span= symbolsCount(post.content)
```js
{{ symbolsTime(post.content) }}
```

##### Symbols Time
```jade
span= symbolsTime(post.content)
```
OR
```jade
span= symbolsTime(post.content, AWL, WPM)
```
Or with predefined parameters:

##### Symbols Count Total
```jade
span= symbolsCountTotal(site)
```js
{{ symbolsTime(post.content, AWL, WPM, Suffix) }}
```

##### Symbols Time Total
```jade
span= symbolsTimeTotal(site)
```
OR
```jade
span= symbolsTimeTotal(site, AWL, WPM)
```
#### Symbols Count Total

#### Parameters
* `AWL` — Average Word Length (chars count in word). Default: `5`. You can check this [here](https://charactercounttool.com).
* EN &asymp; `5`
* RU &asymp; `6`
* CN &asymp; `25`
* `WPM` — Words Per Minute. Default: `200`. You can check this [here](https://wordcounter.net).
* Slow &asymp; `200`
* Normal &asymp; `275`
* Fast &asymp; `350`
```js
{{ symbolsCountTotal(site) }}
```

## Development
#### Symbols Time Total

```bash
cd hexo
git clone https://github.com/theme-next/hexo-symbols-count-time.git node_modules/hexo-symbols-count-time
cd node_modules/hexo-symbols-count-time
```js
{{ symbolsTimeTotal(site) }}
```

### Tests ###
Or with predefined parameters:

```bash
npm install mocha chai --save-dev
npm test
```js
{{ symbolsTimeTotal(site, AWL, WPM, Suffix) }}
```

### Tests with coverage ###
#### Renderers syntax

```bash
npm install -g istanbul
istanbul cover --print both node_modules/.bin/_mocha -- test/index.js
```
SWIG / Nunjucks: `{{` `template` `}}`\
EJS: `<%-` `template` `%>`\
Jade: `span=` `template`
29 changes: 14 additions & 15 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ var getSymbols = function(content) {
return stripHTML(content).length;
};

var getFormatTime = function(minutes) {
var getFormatTime = function(minutes, suffix) {
var fHours = Math.floor(minutes / 60);
var fMinutes = Math.floor(minutes - (fHours * 60));
if (fMinutes < 1) {
fMinutes = '01'; // 0:0 => 0:01
} else if (fMinutes < 10) {
fMinutes = '0' + fMinutes; // 0:9 => 0:09
}
return fHours + ':' + fMinutes;
if (fMinutes < 1) { fMinutes = 1; } // 0 => 1
if (!suffix) { suffix = 'mins.'; } // 1 => 1 mins.
return fHours < 1
? fMinutes + ' ' + suffix // < 59 => 59 mins.
: fHours + ':' + (fMinutes < 10 && (fMinutes = '0' + fMinutes)); // = 61 => 1:01
};

module.exports.symbolsCount = function(content) {
Expand All @@ -27,11 +26,11 @@ module.exports.symbolsCount = function(content) {
return symbolsResult;
};

module.exports.symbolsTime = function(content, awl, wpm) {
if (!awl) { awl = '5'; }
if (!wpm) { wpm = '200'; }
module.exports.symbolsTime = function(content, awl, wpm, suffix) {
if (!awl) { awl = '4'; }
if (!wpm) { wpm = '275'; }
var minutes = Math.round(getSymbols(content) / (awl * wpm));
return getFormatTime(minutes);
return getFormatTime(minutes, suffix);
};

var getSymbolsTotal = function(site) {
Expand All @@ -49,9 +48,9 @@ module.exports.symbolsCountTotal = function(site) {
: Math.round(symbolsResultTotal / 100000) / 10 + 'm'; // > 999k => 1.1m
};

module.exports.symbolsTimeTotal = function(site, awl, wpm) {
if (!awl) { awl = '5'; }
if (!wpm) { wpm = '200'; }
module.exports.symbolsTimeTotal = function(site, awl, wpm, suffix) {
if (!awl) { awl = '4'; }
if (!wpm) { wpm = '275'; }
var minutes = Math.round(getSymbolsTotal(site) / (awl * wpm));
return getFormatTime(minutes);
return getFormatTime(minutes, suffix);
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"eslint": "^4.10.0",
"eslint-config-hexo": "^2.0.0",
"hexo": "^3.2.2",
"hexo-util": "^0.6.3",
"istanbul": "^0.4.5",
"mocha": "^2.5.3"
}
Expand Down
Loading

0 comments on commit dadc4cc

Please sign in to comment.