Browse Source

Use proper Unicode word count; fixes #304

index-subcmd
Clar Charr Vincent Prouillet 6 years ago
parent
commit
da3b0fcf0e
3 changed files with 4 additions and 4 deletions
  1. +1
    -1
      components/utils/Cargo.toml
  2. +2
    -2
      components/utils/src/site.rs
  3. +1
    -1
      docs/content/documentation/templates/pages-sections.md

+ 1
- 1
components/utils/Cargo.toml View File

@@ -6,8 +6,8 @@ authors = ["Vincent Prouillet <prouillet.vincent@gmail.com>"]
[dependencies]
errors = { path = "../errors" }
tera = "0.11"
unicode-segmentation = "1.2"
walkdir = "2"


[dev-dependencies]
tempfile = "3"

+ 2
- 2
components/utils/src/site.rs View File

@@ -1,11 +1,11 @@
use std::collections::HashMap;
use unicode_segmentation::UnicodeSegmentation;

use errors::Result;

/// Get word count and estimated reading time
pub fn get_reading_analytics(content: &str) -> (usize, usize) {
// Only works for latin language but good enough for a start
let word_count: usize = content.split_whitespace().count();
let word_count: usize = content.unicode_words().count();

// https://help.medium.com/hc/en-us/articles/214991667-Read-time
// 275 seems a bit too high though


+ 1
- 1
docs/content/documentation/templates/pages-sections.md View File

@@ -63,7 +63,7 @@ extra: HashMap<String, Any>;
pages: Array<Pages>;
// Direct subsections to this section, sorted by subsections weight
subsections: Array<Section>;
// Naive word count, will not work for languages without whitespace
// Unicode word count
word_count: Number;
// Based on https://help.medium.com/hc/en-us/articles/214991667-Read-time
reading_time: Number;


Loading…
Cancel
Save