
Added a check for whether short is true or false, rather than just
checking if it exists. This ensures that if short is set to false,
it will still use the long date format if it's available.
♻️ refactor: move the conditional around the date output, so it only
needs to check `short` once
35 lines
997 B
HTML
35 lines
997 B
HTML
{% macro format_date(date, short) %}
|
|
|
|
{% if config.extra.short_date_format and short %}
|
|
{{ date | date(format=config.extra.short_date_format) }}
|
|
{% elif config.extra.long_date_format and not short %}
|
|
{{ date | date(format=config.extra.long_date_format) }}
|
|
{% else %}
|
|
{% set day = date | date(format='%-d') | int %}
|
|
|
|
{% if day in [11, 12, 13] %}
|
|
{% set suffix = "th" %}
|
|
{% else %}
|
|
{% set last_digit = day % 10 %}
|
|
{% if last_digit == 1 %}
|
|
{% set suffix = "st" %}
|
|
{% elif last_digit == 2 %}
|
|
{% set suffix = "nd" %}
|
|
{% elif last_digit == 3 %}
|
|
{% set suffix = "rd" %}
|
|
{% else %}
|
|
{% set suffix = "th" %}
|
|
{% endif %}
|
|
{% endif %}
|
|
|
|
{# Return the date. #}
|
|
{{ date | date(format="%-d") }}{{ suffix }}
|
|
{% if short == true %}
|
|
{{ date | date(format="%b %Y") }}
|
|
{% else %}
|
|
{{ date | date(format="%B %Y") }}
|
|
{% endif %}
|
|
{% endif %}
|
|
|
|
{% endmacro %}
|