不使用自定义插件在Jekyll中格式化数字
我正在使用Jekyll集合来管理课程的元素。每个元素在其YAML前端有一个持续时间:不使用自定义插件在Jekyll中格式化数字,jekyll,Jekyll,我正在使用Jekyll集合来管理课程的元素。每个元素在其YAML前端有一个持续时间: --- duration: 5 --- 我在元素上循环计算每个元素的开始时间: {% assign current = 0 %} <table> {% for element in site.elements %} <tr> <td>{{ forloop.index }}</td> <td>{{ element.title }}&
---
duration: 5
---
我在元素上循环计算每个元素的开始时间:
{% assign current = 0 %}
<table>
{% for element in site.elements %}
<tr>
<td>{{ forloop.index }}</td>
<td>{{ element.title }}</td>
<td>{{ current | divided_by: 60 }}:{{ current | modulo: 60 }}</td>
</tr>
{% assign current = current | plus: element.duration %}
{% endfor %}
</table>
而不是:
09:05
我想不出一种方法来使用日期格式来获得我想要的输出,因为“时间”只是分钟,而不是日期。有没有办法用指定的小数位数和前导零在Jekyll中格式化数字?您可以使用条件格式化:
{% assign h = timeInMinutes | divided_by: 60 %}
{% if h <= 10 %}{% assign h = h | prepend: '0' %}{% endif %}
{% assign m = timeInMinutes | modulo: 60 %}
{% if m <= 10 %}{% assign m = m | prepend: '0' %}{% endif %}
{{ h }}:{{ m }}
谢谢-但是哇,这让我回到了Fortran的早期。
{% assign h = timeInMinutes | divided_by: 60 %}
{% if h <= 10 %}{% assign h = h | prepend: '0' %}{% endif %}
{% assign m = timeInMinutes | modulo: 60 %}
{% if m <= 10 %}{% assign m = m | prepend: '0' %}{% endif %}
{{ h }}:{{ m }}
{{ timeInMinutes | divided_by: 60 | plus: 100 | slice: 1, 2 }}
:
{{ timeInMinutes | modulo: 60 | plus: 100 | slice: 1, 2 }}