Skip to content

Commit

Permalink
Add word counter
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed Oct 5, 2018
1 parent 63792fe commit 6cc040f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions _conf_wc.yml
@@ -0,0 +1 @@
calc_word_count: true
14 changes: 14 additions & 0 deletions cat.html
@@ -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 changes: 17 additions & 0 deletions utils/_count_words.js
@@ -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 changes: 4 additions & 0 deletions utils/count_words.sh
@@ -0,0 +1,4 @@
#!/bin/bash

jekyll build --config _config.yml,_conf_wc.yml
./utils/_count_words.js

0 comments on commit 6cc040f

Please sign in to comment.