Skip to content

Commit

Permalink
Add readtime daattali#594
Browse files Browse the repository at this point in the history
Add code that calculates estimated read time
  • Loading branch information
rubyontherez authored and Matt Erickson committed Apr 24, 2020
1 parent 3516935 commit 98386a5
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions _includes/readtime.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!--- "ReadTime on GitHub Jekyll" (c) 2020 Ruby Griffith Ramirez, MIT License -->

{% assign ReadTime = page.content | strip_html | number_of_words %}
{% assign calcReadTime = ReadTime | float %}
{% assign finalReadTime = calcReadTime | divided_by:200 | round: 2 %}
{% assign number = finalReadTime | round %}
{% if number >= 1 %}
{% assign yesReadTime = number | append: " minute read" %}
&middot; {{ yesReadTime }}
{% elsif number < 1 %}
{% assign minReadTime = '&lt; 1 minute read' %}
&middot; {{ minReadTime }}
{% else %}
{% assign nilReadTime = number | replace:'0',' ' %}
{{ nilReadTime }}
{% endif %}

0 comments on commit 98386a5

Please sign in to comment.