Add word counter
This commit is contained in:
parent
63792fe2ac
commit
6cc040fd0c
1
_conf_wc.yml
Normal file
1
_conf_wc.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
calc_word_count: true
|
14
cat.html
Normal file
14
cat.html
Normal 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
17
utils/_count_words.js
Executable 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
4
utils/count_words.sh
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
jekyll build --config _config.yml,_conf_wc.yml
|
||||||
|
./utils/_count_words.js
|
Loading…
Reference in New Issue
Block a user