Skip to content

🌔 An article estimated read time plugin for Pelican static site generator. Python 3.6 optimized. ⌚

Notifications You must be signed in to change notification settings

dp0/pelican-readtime

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

'pelican-readtime' - A Read Time Plugin for Pelican Static Site Generator

An article estimated read time plugin for Pelican static site generator. After Pelican generated the content of each page, the plugin read through the generated HTML content and strip all the tags, count all the word, then utilize average human read speed to calculate the read time of each article. The read time is passed over to the 'content' object of the article so Jinja template can use it to display the read time on wherever appropriate.

Demo

The plugin can be embedded into your site's template and look like this:
Pelican Read Time Demo
An example can be found in my own blog here.

Usage

This plugin only uses standard modules(re, html, math, etc), so no extra module installation like BeautifuSoup. To use it, just add the plugin name to the pelicanconf.py file.

    PLUGINS=[ ... , 'pelican-readtime']

Optionally, you can also configure tags in the content to ignore, such as ingoring any content in inlined SVGs:

    READTIME_IGNORE_TAGS = ['svg']

Then you can put the following code in whichever template you what, like article.html.

    {% if article.readtime %}
    <div><b>Read in {{article.readtime.minutes}} min.</b></div>
    {% endif %}

You can also add some styling to it like so:

    {% if article.readtime %}
    <span><p style="text-align:right; color:#aaaaaa; ">&nbsp Estimated read time: {{article.readtime.minutes}} min.</p></span>
    {% endif %}

Credits

This is a revised version of jmaister's readtime plugin. I added some more comments and tweaked the code so it runs smoothly on Python 3.6

Reference

[1] Wikipedia - Words per minute
[2] Medium - Read Time

About

🌔 An article estimated read time plugin for Pelican static site generator. Python 3.6 optimized. ⌚

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%