Undefined word_per_minutes parameter division by zero

If the parameter words_per_minute at _config.yml is not defined and the template says that must show read_time then will be divide a number by zero, a fix is verify that parameter and show a message when this is empty or zero. already localized for spanish
This commit is contained in:
Sergio C. Orozco Torres 2016-06-07 01:03:59 -05:00
parent 1510947bf6
commit 01cfcf0f3b
2 changed files with 13 additions and 5 deletions

View file

@ -27,6 +27,7 @@ en: &DEFAULT_EN
website_label : "Website" website_label : "Website"
email_label : "Email" email_label : "Email"
recent_posts : "Recent Posts" recent_posts : "Recent Posts"
undefined_wpm : "Undefined parameter words_per_minute at _config.yml"
en-US: en-US:
<<: *DEFAULT_EN <<: *DEFAULT_EN
en-UK: en-UK:
@ -59,6 +60,7 @@ es: &DEFAULT_ES
website_label : "Sitio web" website_label : "Sitio web"
email_label : "Email" email_label : "Email"
recent_posts : "Entradas recientes" recent_posts : "Entradas recientes"
undefined_wpm : "Parametro words_per_minute (Palabras por minuto) no definido en _config.yml"
es-ES: es-ES:
<<: *DEFAULT_ES <<: *DEFAULT_ES
es-CO: es-CO:

View file

@ -1,9 +1,12 @@
{% if post.read_time %} {% if post.read_time %}
{% assign words = post.content | strip_html | number_of_words %} {% assign words = post.content | strip_html | number_of_words %}
{% elsif page.read_time %} {% elsif page.read_time %}
{% assign words = page.content | strip_html | number_of_words %} {% assign words = page.content | strip_html | number_of_words %}
{% endif %} {% endif %}
{% if site.words_per_minute %}
{% if words < 180 %} {% if words < 180 %}
{{ site.data.ui-text[site.locale].less_than }} 1 {{ site.data.ui-text[site.locale].minute_read }} {{ site.data.ui-text[site.locale].less_than }} 1 {{ site.data.ui-text[site.locale].minute_read }}
{% elsif words < 360 %} {% elsif words < 360 %}
@ -11,3 +14,6 @@
{% else %} {% else %}
{{ words | divided_by:site.words_per_minute }} {{ site.data.ui-text[site.locale].minutes_read }} {{ words | divided_by:site.words_per_minute }} {{ site.data.ui-text[site.locale].minutes_read }}
{% endif %} {% endif %}
{% else %}
{{ site.data.ui-text[site.locale].undefined_words_per_minute }}
{% endif %}