Alex Waite 873c525b46 Always specify parser for Beautiful Soup; fixes extraneous tags 8 years ago
..
__init__.py d38b4a8028 Initial commit of Post Statistics plugin 11 years ago
post_stats.py 873c525b46 Always specify parser for Beautiful Soup; fixes extraneous tags 8 years ago
readability.py 855f87300a [post_stats] Python 3 compatibility 9 years ago
readme.rst f629e3b012 Tidy up readme 11 years ago

readme.rst

Post Statistics
==================

A Pelican plugin to calculate various statistics about a post and store them in an article.stats dictionary:

- ``wc``: how many words
- ``read_mins``: how many minutes would it take to read this article, based on 250 wpm (http://en.wikipedia.org/wiki/Words_per_minute#Reading_and_comprehension)
- ``word_counts``: frquency count of all the words in the article; can be used for tag/word clouds
- ``fi``: Flesch-kincaid Index/ Reading Ease (see: http://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests)
- ``fk``: Flesch-kincaid Grade Level

Example:

.. code-block:: python

{
'wc': 2760,
'fi': '65.94',
'fk': '7.65',
'word_counts': Counter({u'to': 98, u'a': 90, u'the': 83, u'of': 50, ...}),
'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'] }}



The ``word_counts`` variable is a python ``Counter`` dictionary and looks something like this, with each unique word and it's frequency:

.. code-block:: python

Counter({u'to': 98, u'a': 90, u'the': 83, u'of': 50, u'karma': 50, .....

and can be used to create a tag/word cloud for a post.

Requirements
----------------

`post_stats` requires BeautifulSoup.

.. code-block:: console

$ pip install beautifulsoup4