| 1 |
--- |
| 2 |
title: ReadingTime |
| 3 |
description: Returns the estimated reading time, in minutes, for the given page. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
returnType: int |
| 9 |
signatures: [PAGE.ReadingTime] |
| 10 |
--- |
| 11 |
|
| 12 |
The estimated reading time is calculated by dividing the number of words in the content by the reading speed. |
| 13 |
|
| 14 |
By default, Hugo assumes a reading speed of 212 words per minute. For CJK languages, it assumes 500 words per minute. |
| 15 |
|
| 16 |
```go-html-template |
| 17 |
{{ printf "Estimated reading time: %d minutes" .ReadingTime }} |
| 18 |
``` |
| 19 |
|
| 20 |
Reading speed varies by language. Create language-specific estimated reading times on your multilingual project using site parameters. |
| 21 |
|
| 22 |
{{< code-toggle file=hugo >}} |
| 23 |
[languages] |
| 24 |
[languages.de] |
| 25 |
contentDir = 'content/de' |
| 26 |
label = 'Deutsch' |
| 27 |
locale = 'de-DE' |
| 28 |
weight = 2 |
| 29 |
[languages.de.params] |
| 30 |
reading_speed = 179 |
| 31 |
[languages.en] |
| 32 |
contentDir = 'content/en' |
| 33 |
label = 'English' |
| 34 |
locale = 'en-US' |
| 35 |
weight = 1 |
| 36 |
[languages.en.params] |
| 37 |
reading_speed = 228 |
| 38 |
{{< /code-toggle >}} |
| 39 |
|
| 40 |
Then in your template: |
| 41 |
|
| 42 |
```go-html-template |
| 43 |
{{ $readingTime := div (float .WordCount) .Site.Params.reading_speed }} |
| 44 |
{{ $readingTime = math.Ceil $readingTime }} |
| 45 |
``` |
| 46 |
|
| 47 |
We cast the `.WordCount` to a float to obtain a float when we divide by the reading speed. Then round up to the nearest integer. |