feat: add get reading time function
This commit is contained in:
parent
01a36696e6
commit
87cf6bca65
1 changed files with 41 additions and 0 deletions
41
_includes/functions/get_reading_time.html
Normal file
41
_includes/functions/get_reading_time.html
Normal file
|
@ -0,0 +1,41 @@
|
|||
{% 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 %}
|
Loading…
Reference in a new issue