getpelican/pelican-plugins — pull request #38 by dflock (2013-06-24 05:51:23+00:00)
Title: Post stats

A Pelican plugin to calculate various statistics about a post and store them in an ``article.stats`` dictionary. Includes time to read, word count, word frequency and Flesch-kincaid stats.

The returned ``article.stats`` dictionary contains the following:

- ``wc``: how many words
- ``read_mins``: how many minutes would it take to read this article, `based on 250 wpm `_
- ``word_counts``: frquency count of all the words in the article; can be used for tag/word clouds
- ``fi``: `Flesch-kincaid `_ Index/ Reading Ease
- ``fk``: Flesch-kincaid Grade Level

For example:

.. code-block:: python

{
'wc': 2760,
'fi': '65.94',
'fk': '7.65',
'word_counts': Counter({u'to': 98, u'a': 90, ...}),
'read_mins': 12
}

This allows you to output these values in your templates, like this, for example:

.. code-block:: html+jinja

~{{ article.stats['read_mins'] }} min read

Flesch-kincaid Index/ Reading Ease: {{ article.stats['fi'] }}

Flesch-kincaid Grade Level: {{ article.stats['fk'] }}

Requires BeautifulSoup4

Full write-up here: http://duncanlock.net/blog/2013/06/23/post-statistics-plugin-for-pelican/