Add word counter

master
rubenwardy 2018-10-05 16:08:35 +01:00
parent 63792fe2ac
commit 6cc040fd0c
No known key found for this signature in database
GPG Key ID: A1E29D52FF81513C
4 changed files with 36 additions and 0 deletions

1
_conf_wc.yml Normal file
View File

@ -0,0 +1 @@
calc_word_count: true

14
cat.html Normal file
View File

@ -0,0 +1,14 @@
---
layout: none
---
{% if site.calc_word_count %}
{% assign chapters = site.en | sort: "idx" %}
{% for chapter in chapters %}
{% unless chapter.homepage %}
{{ chapter.content }}
{% endunless %}
{% endfor %}
{% else %}
Cat disabled.
{% endif %}

17
utils/_count_words.js Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/node
var wordCount = require('html-word-count');
var fs = require("fs");
var jsdom = require("jsdom");
var text = fs.readFileSync("_site/cat.html");
const { JSDOM } = jsdom;
const { window } = new JSDOM(text);
const { document } = (window).window;
global.document = document;
var $ = require('jquery')(window);
$("pre").remove();
console.log(wordCount(document.documentElement.innerHTML)); // 2

4
utils/count_words.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
jekyll build --config _config.yml,_conf_wc.yml
./utils/_count_words.js