readme.rst 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. Post Statistics
  2. ==================
  3. A Pelican plugin to calculate various statistics about a post and store them in an article.stats dictionary:
  4. - ``wc``: how many words
  5. - ``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)
  6. - ``word_counts``: frquency count of all the words in the article; can be used for tag/word clouds
  7. - ``fi``: Flesch-kincaid Index/ Reading Ease (see: http://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests)
  8. - ``fk``: Flesch-kincaid Grade Level
  9. Example:
  10. .. code-block:: python
  11. {
  12. 'wc': 2760,
  13. 'fi': '65.94',
  14. 'fk': '7.65',
  15. 'word_counts': Counter({u'to': 98, u'a': 90, u'the': 83, u'of': 50, ...}),
  16. 'read_mins': 12
  17. }
  18. This allows you to output these values in your templates, like this, for example:
  19. .. code-block:: html+jinja
  20. <p title="~{{ article.stats['wc'] }} words">~{{ article.stats['read_mins'] }} min read</p>
  21. <ul>
  22. <li>Flesch-kincaid Index/ Reading Ease: {{ article.stats['fi'] }}</li>
  23. <li>Flesch-kincaid Grade Level: {{ article.stats['fk'] }}</li>
  24. </ul>
  25. The ``word_counts`` variable is a python ``Counter`` dictionary and looks something like this, with each unique word and it's frequency:
  26. .. code-block:: python
  27. Counter({u'to': 98, u'a': 90, u'the': 83, u'of': 50, u'karma': 50, .....
  28. and can be used to create a tag/word cloud for a post.
  29. Requirements
  30. ----------------
  31. `post_stats` requires BeautifulSoup.
  32. .. code-block:: console
  33. $ pip install beautifulsoup4