reading time
[pinopress.git] / modules / readingtime
diff --git a/modules/readingtime b/modules/readingtime
new file mode 100755 (executable)
index 0000000..7983314
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+## module for getting estimated time to read an article
+## usage:
+##    readingtime [file]
+## exports:
+##    READING_TIME in minutes
+
+## config vars
+wordsPerMinute=250
+
+# first clean special symbols and lines with whitespace
+wordcount=`sed -e 's/[^A-Za-z0-9 ]//g' -e '/^\s*$/d' "$1" | wc -w`
+export READING_TIME=$(expr $(expr $wordcount + $wordsPerMinute) / $wordsPerMinute)