Use Zola's built-in reading time variable instead of the custom implementation (fixes #102)

This commit is contained in:
daudix
2024-10-12 00:21:16 +03:00
parent d22922f46b
commit a7e1112791
3 changed files with 10 additions and 14 deletions

View File

@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add "DRAFTED" watermark to drafted posts.
### Changed
- Rename `show_read_time` to `show_reading_time`.
- Use Zola's built-in reading time variable instead of the custom implementation (#102).
### Fixed
- Fix navbar mods having broken border radius.

View File

@ -131,10 +131,7 @@ source_url = "https://codeberg.org/daudix/duckquill"
# See https://www.getzola.org/documentation/content/syntax-highlighting/
show_copy_button = true
# Whether to show estimated read time in posts.
# Calculated using the simple math: number of words ÷ words per minute.
show_read_time = true
#
# words_per_minute = 200
show_reading_time = true
#
# Whether to show a share button in articles.
# Uses https://shareopenly.org.

View File

@ -45,24 +45,18 @@
<h1>{{ page.title }}</h1>
{%- if page.authors or config.extra.show_read_time -%}
{%- if page.authors or config.extra.show_reading_time -%}
<p>
<small>
{%- if page.authors -%}
<span>{% include "partials/authors.html" -%}</span>
{%- if config.extra.show_read_time -%}
{%- if config.extra.show_reading_time -%}
<span></span>
{%- endif -%}
{%- endif -%}
{%- if config.extra.show_read_time -%}
{%- set words = page.content | striptags | safe | wordcount -%}
{%- set words_per_minute = config.extra.words_per_minute | default(value=200) -%}
{%- set number_of_minutes = words / words_per_minute | round -%}
{%- if number_of_minutes == 0 -%}
{%- set number_of_minutes = 1 -%}
{%- endif -%}
<span>{{ macros_translate::translate(key="minutes_read", number=number_of_minutes, default="$NUMBER minute read", language_strings=language_strings) }}</span>
{%- if config.extra.show_reading_time -%}
<span>{{ macros_translate::translate(key="minutes_read", number=page.reading_time, default="$NUMBER minute read", language_strings=language_strings) }}</span>
{%- if page.taxonomies -%}
<span></span>
{%- endif -%}