krata/_includes/read-time.html

31 lines
903 B
HTML
Raw Normal View History

2020-12-17 08:17:21 +01:00
<!--
Calculate the post's reading time, and display the word count in tooltip
-->
2021-07-20 19:01:09 +02:00
2020-12-17 08:17:21 +01:00
{% assign words = include.content | strip_html | number_of_words: "auto" %}
<!-- words per minute -->
2021-07-20 19:01:09 +02:00
{% assign wpm = 180 %}
{% assign min_time = 1 %}
{% assign read_time = words | divided_by: wpm %}
2020-12-17 08:17:21 +01:00
{% unless read_time > 0 %}
{% assign read_time = min_time %}
2020-12-17 08:17:21 +01:00
{% endunless %}
2021-07-20 19:01:09 +02:00
{% capture read_prompt %}
{{- site.data.locales[lang].post.read_time.prompt -}}
2021-07-20 19:01:09 +02:00
{% endcapture %}
2020-12-17 08:17:21 +01:00
<!-- return element -->
2021-07-20 19:01:09 +02:00
<span class="readtime" data-toggle="tooltip" data-placement="bottom"
title="{{ words }} {{ site.data.locales[lang].post.words }}">
{{- read_time -}}{{" "}}{{- site.data.locales[lang].post.read_time.unit -}}
2021-07-20 19:01:09 +02:00
{%- if include.prompt -%}
2021-08-25 19:26:16 +02:00
{% assign _prompt_words = read_prompt | number_of_words: 'auto' %}
{% unless _prompt_words > 1 %}{{" "}}{% endunless %}{{ read_prompt }}
2021-07-20 19:01:09 +02:00
{%- endif -%}
2020-12-17 08:17:21 +01:00
</span>