DEV Community


How to add approx read time on posts in Jigsaw?

rishpandey profile image Rish Pandey Originally published at on ・1 min read

My current blog is developed using Jigsaw and their awesome template.

Jigsaw is a framework for rapidly building static sites using the same modern tooling that powers your web applications.

I absolutely love the design and made little to no changes on it. One thing I very much needed is to show read time on each article. This is how I accomplished it.

  • Add a new helper in config.php.
'getReadTime' => function ($page, $wpm = 150) {
        $content = strip_tags($page->getContent());
        $word_count = str_word_count($content);
        return ceil($word_count / $wpm);

Enter fullscreen mode Exit fullscreen mode
  • Use the helper in post-preview-inline.blade.php. In blog template this file is used to give an inline preview of posts.
    href="{{ $post->getUrl() }}"
    title="Read more - {{ $post->title }}"
    class="uppercase font-semibold tracking-wide mb-2"
    {{ $post->getReadTime() }} Minutes Read 

Enter fullscreen mode Exit fullscreen mode

Discussion (0)

Forem Open with the Forem app