blog/_includes/functions/get_reading_time.html
2020-07-16 19:24:05 +08:00

41 lines
845 B
HTML

{% if include.article %}
{% assign article = include.article %}
{% endif %}
{% if include.speed %}
{% assign speed = include.speed %}
{% else %}
{% assign speed = 160 %}
{% endif %}
{% assign total_mins = article
| number_of_words
| divided_by: speed
| at_least: 1 %}
{% assign hours = total_mins | divided_by: 60 %}
{% assign mins = total_mins | modulo: 60 %}
{% assign return = "About" %}
{% if hours > 0 %}
{% assign unit = "hour" %}
{% if hours > 1 %}
{% assign unit = unit | append: "s" %}
{% endif %}
{% assign return = return
| append: " "
| append: hours
| append: " "
| append: unit %}
{% endif %}
{% assign unit = "min" %}
{% if mins > 1 %}
{% assign unit = unit | append: "s" %}
{% endif %}
{% assign return = return
| append: " "
| append: mins
| append: " "
| append: unit %}