Reading Time
digitalinferno opened this issue · 2 comments
digitalinferno commented
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
I got nothing to add, if it works, that's great 👍
github-actions commented
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! 👍