summaryrefslogtreecommitdiff
path: root/_includes/functions/get_reading_time.html
blob: e1d23fe508b3e1414f0fc339e0c923ae16959273 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{% if include.params.article %}
  {% assign article = include.params.article %}
{% endif %}

{% if include.params.lang %}
  {% assign lang = include.params.lang %}
{% else %}
  {% assign lang = lang | default: site.lang | default: "en" %}
{% endif %}

{% if include.params.speed %}
  {% assign speed = include.params.speed %}
{% else %}
  {% assign speed = 160 %}
{% endif %}

{% assign words = article | number_of_words %}

{% if lang != "en" %}
  {% assign words = words
    | times: 0.6
    | round %}
  {% assign words = article
    | strip_html
    | strip_newlines
    | size
    | times: 0.4
    | plus: words
    | round %}
{% endif %}

{% assign total_mins = 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 %}