monkeyWzr / hugo-theme-cactus

Cactus theme for hugo
MIT License
537 stars 338 forks source link

Add read time to posts #42

Closed switchswap closed 3 years ago

switchswap commented 3 years ago

I added read-time to posts and made it configurable!

Here's a picture of it in action on the dark theme (thought it works on all themes): firefox_2021-04-04_05-06-12

It's also configurable via the config with a new boolean setting, showReadTime, which I've set to default as false.

I updated the sample config in exampleTheme to reflect this as well.

vdovhanych commented 3 years ago

This looks cool but it has a minor bug, if you set post category this happens. image

vdovhanych commented 3 years ago

Was fixed for me by putting the time read block before category block in. `{{ $showReadTime := .Site.Params.showReadTime | default false }} {{if $showReadTime}}

{{ $readTime := math.Round (div (countwords .Content) 220.0) }} {{ $readTime }} minute read
  {{ end }}
    {{ if gt .Params.categories 0 }}
    <div class="article-category">`

image

switchswap commented 3 years ago

Oh, whoops! Thanks for catching that! I'll fix it up right away!

switchswap commented 3 years ago

This issue should be fixed with that lastest commit. :)