web/_includes/read-time.html

30 lines
907 B
HTML
Raw Normal View History

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