Skip to content

Commit d0ddcf6

Browse files
authored
feat(post): add .ReadingTime (#312)
* feat(post): add .ReadingTime display estimated reading time before date (like Medium.com) https://gohugo.io/methods/page/readingtime/ * feat(post): hide .ReadingTime behind config key * docs(basics): add displayReadingTime
1 parent 7a0d21e commit d0ddcf6

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

exampleSite/content/posts/theme-documentation-basics.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,15 @@ If any post front matter contains `weight`, the posts will not appear by Date. S
328328
togglePreviousAndNextButtons = "false"
329329
```
330330

331+
### Reading time
332+
333+
Display a post's [estimated reading time](https://gohugo.io/methods/page/readingtime/) in minutes.
334+
335+
```toml
336+
[params]
337+
displayReadingTime = false
338+
```
339+
331340
### robots.txt
332341

333342
[Automatically generate](https://gohugo.io/templates/robots/) a `robots.txt` file, used to ['manage crawler traffic to your site'](https://developers.google.com/search/docs/crawling-indexing/robots/intro).

layouts/partials/post.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,16 @@ <h1>{{ .Title | markdownify }}</h1>
2424
{{ end }}
2525

2626
{{ if $displayDate }}
27-
<p class="post-date">{{ dateFormat (or .Site.Params.dateFormat "January 2, 2006") .Date}}
28-
{{ if lt .Date .Lastmod }} | Updated {{ dateFormat (or .Site.Params.dateFormat "January 2, 2006") .Lastmod }}{{ end }}
27+
<p class="post-date">
28+
{{ if (eq .Site.Params.DisplayReadingTime true) }}
29+
{{ .ReadingTime }} min read |
30+
{{ end }}
31+
32+
{{ dateFormat (or .Site.Params.dateFormat "January 2, 2006") .Date }}
33+
34+
{{ if lt .Date .Lastmod }}
35+
| Updated {{ dateFormat (or .Site.Params.dateFormat "January 2, 2006") .Lastmod }}
36+
{{ end }}
2937
</p>
3038
{{ end }}
3139

0 commit comments

Comments
 (0)