diff options
author | Rise <8315221+AmazingRise@users.noreply.github.com> | 2020-05-17 17:45:58 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-17 17:45:58 +0300 |
commit | 2d2b197f3637abdbc1315e3ba5f84a7b0c16f235 (patch) | |
tree | ae3430cd697da9f37daf3613ebd2e494e142af33 | |
parent | 99a2087a8dea1de6278bf382bb6f433fdb09c332 (diff) | |
parent | ea868e648b67804d07cf0c440fa980fab99a7fcf (diff) |
Merge pull request #36 from thebestwj/reading-time
Add reading time in home page, hide minute if less than a minute
-rw-r--r-- | layouts/_default/single.html | 2 | ||||
-rw-r--r-- | layouts/index.html | 15 |
2 files changed, 17 insertions, 0 deletions
diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 83026c0..d2c9bcd 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -52,7 +52,9 @@ {{ $minutes := math.Floor (div $readTime 60) }} {{ $seconds := mod $readTime 60 }} + {{ if gt $minutes 0}} {{ $minutes }} {{ cond (eq $minutes 1) "minute" "min" }} + {{ end }} {{ $seconds }} {{ cond (eq $seconds 1) "second" "s" }}. {{ end }} </div> diff --git a/layouts/index.html b/layouts/index.html index a61a66d..48cf427 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -17,6 +17,21 @@ </div> <div class="post-item-meta"> {{ .PublishDate.Format "2006-01-02" }} +   + <!-- Reading Time Start --> + {{ if .Site.Params.enableReadingTime }} + <i class="material-icons" style="font-size:10px">schedule</i> + {{ $readTime := mul (div (countwords .Content) 220.0) 60 }} + + {{ $minutes := math.Floor (div $readTime 60) }} + {{ $seconds := mod $readTime 60 }} + + {{ if gt $minutes 0}} + {{ $minutes }} {{ cond (eq $minutes 1) "minute" "min" }} + {{ end }} + {{ $seconds }} {{ cond (eq $seconds 1) "second" "s" }} + {{ end }} + <!-- Reading Time End --> </div> </div> {{ $featured_image := .Params.featured_image }} |