diff options
author | jeffreytse <jeffreytse.mail@gmail.com> | 2020-07-16 19:24:05 +0800 |
---|---|---|
committer | jeffreytse <jeffreytse.mail@gmail.com> | 2020-07-16 19:24:05 +0800 |
commit | 87cf6bca650a68432b96169840132416b5dd26dc (patch) | |
tree | 7f230d19f16cd28064fd03952ff05dcb22a67365 | |
parent | 01a36696e666d5b05d45aa9ec03f91f59725223d (diff) |
feat: add get reading time function
-rw-r--r-- | _includes/functions/get_reading_time.html | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/_includes/functions/get_reading_time.html b/_includes/functions/get_reading_time.html new file mode 100644 index 0000000..d28b69c --- /dev/null +++ b/_includes/functions/get_reading_time.html @@ -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 %} |