diff options
author | Florian Engel <vlow+git@turbocache3000.de> | 2021-09-18 20:52:58 +0300 |
---|---|---|
committer | Florian Engel <vlow+git@turbocache3000.de> | 2021-09-18 20:52:58 +0300 |
commit | 4b6cecc495d3f427035c1771cad4e5323188568f (patch) | |
tree | 2993da524770a92f4e08bd229934f4613701a6f2 | |
parent | 61d85789b3e4aaf7305ce7c16b79e6afa12cd867 (diff) |
Add word count and reading time options
-rwxr-xr-x | exampleSite/config.toml | 2 | ||||
-rwxr-xr-x | layouts/_default/li.html | 1 | ||||
-rwxr-xr-x | layouts/_default/single.html | 2 | ||||
-rw-r--r-- | layouts/partials/post_metadata.html | 12 |
4 files changed, 17 insertions, 0 deletions
diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 7910da0..bc88960 100755 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -9,6 +9,8 @@ googleAnalytics = "Your Google Analytics tracking id" [params] paginate = 10 + wordCount = true + readingTime = true custom_css = ["/css/custom.css"] # Social accounts. Link to these accounts are displayed in the header and # footer diff --git a/layouts/_default/li.html b/layouts/_default/li.html index 52b0b85..d470649 100755 --- a/layouts/_default/li.html +++ b/layouts/_default/li.html @@ -3,6 +3,7 @@ <h2 class="c-title c-article__title"><a href="{{ .Permalink }}">{{ .Title }}</a></h2> <p class="c-article__meta"> {{ partial "timestamp.html" . }} + {{ partial "post_metadata.html" . }} </p> </header> <div class="c-article__summary"> diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 1ccc927..c4e01ba 100755 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -9,6 +9,8 @@ {{ partial "timestamp.html" . }} </div> {{ end }} + {{ partial "post_metadata.html" . }} + </div> {{ range .Params.tags }} <a href="{{ $baseurl }}/tags/{{ . | urlize }}" class="c-tag">{{ . }}</a> {{ end }} diff --git a/layouts/partials/post_metadata.html b/layouts/partials/post_metadata.html new file mode 100644 index 0000000..b14c162 --- /dev/null +++ b/layouts/partials/post_metadata.html @@ -0,0 +1,12 @@ +{{ if .Param "wordCount" }} +| {{ .WordCount }} words +{{ end }} +{{ if .Param "readingTime" }} + {{ if gt .ReadingTime 1 }} + {{ .Scratch.Set "readingTime" "mins" }} + {{ else }} + {{ .Scratch.Set "readingTime" "min" }} + {{ end }} + | ~{{.ReadingTime}} {{ .Scratch.Get "readingTime" }} +{{ end }} + |