Arithmetic calculation on a liquid template in Jekyll to calculate the estimated reading time

I started using Jekyll1 week ago without any knowledge of Ruby, and I would like to implement the following functionality.

From the documentation, Jekyll I can use the following template to calculate words in an article:

{{ page.content | number_of_words }}

I would like to use this information to calculate the approximate reading time of the article in minutes, based on an average assumption 200 words per minute. Which gives the following simple formula:

number_of_words / 200

Not sure, but based on what I read about Ruby, I should use it {{ page.content | number_of_words }} {% %}to do my calculations, but I'm not sure I can use it {{ page.content | number_of_words }} {{ page.content | number_of_words }}inside to do the division.

Here is what I have now:

.html document:

.
.
<p class="meta">
    {% print {{number_of_words}} / 200 %}
</p>
.
.

, number_of_words , , , print . ?

+4
1

Jekyll Ruby, Ruby . Liquid, , , .

tags (Jekyll ), {% %}, , Erb, <% %> Ruby.

Liquid , , divided_by, , , , :

{{ page.content | number_of_words | divided_by: 200 }}

, , , , , 200, . , > 0, assign ( ) if :

{% assign read_time = page.content | number_of_words | divided_by: 200 %}

{% if read_time > 0 %}
Read time: {{ read_time }}
{% endif %}
+5

Source: https://habr.com/ru/post/1628598/


All Articles