picocms / Pico

Pico is a stupidly simple, blazing fast, flat file CMS.
http://picocms.org/
MIT License
3.81k stars 616 forks source link

Reading Time #688

Closed digitalinferno closed 4 months ago

digitalinferno commented 5 months ago

I wrote a small plugin. In reality, a few lines in Twig would have been enough, but I enjoyed practicing a little bit.

class PicoReadingTime extends AbstractPicoPlugin {

    const API_VERSION = 3;
    protected $enabled = true;   

    public function onContentLoaded(&$content)
    {
        $words = str_word_count(strip_tags($content));
        $time = ceil($words / 238);
        $this->read = $time;
    }

    public function  onPageRendering(&$twig, &$twigVariables)
    {
        $twigVariables['ReadingTime']  =  $this->read;
    }

}

It reads the number of words in the content and provides an estimate of the required reading time. It works... so it shouldn't be too bad. If you take a look, it would make me happy.

PhrozenByte commented 5 months ago

I got nothing to add, if it works, that's great :+1:

github-actions[bot] commented 4 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! :+1: