♻️ refactor: format date as "6 July 2049"

Follows Oxford's and other formal style manuals.
main
welpo 2 years ago
parent 7195734d59
commit 4b18391c18
No known key found for this signature in database
GPG Key ID: A2F978CF4EC1F5A6

@ -16,9 +16,7 @@ highlight_code = true
highlight_theme = "css"
[extra]
use_cdn = false
date_format = "" # If unset, uses format: "1st January 2049"
date_format = "" # If unset, uses format: "6 July 2049" ("%d %B %Y")
# Custom separator used in title tag and posts metadata (between date, time to read, and tags).
separator = "•"

@ -1,5 +1,4 @@
{% import "macros/list_posts.html" as macros_list_posts %}
{% import "macros/format_date.html" as macros_format_date %}
{% import "macros/page_header.html" as macros_page_header %}
{% import "macros/page_desc.html" as macros_page_desc %}
{% import "macros/content.html" as macros_content %}

@ -21,7 +21,7 @@
<div class="meta">
{%- if page.date %}
{{ macros_format_date::format_date(date=page.date) }}
{{ page.date | date(format=config.extra.date_format | default (value="%d %B %Y")) }}
{% endif -%}
{% if page.draft %}
<span class="draft-label">DRAFT</span>

@ -13,7 +13,7 @@
{% endif %}
{% if page.date %}
<span>{{ macros_format_date::format_date(date=page.date) }}</span>
<span>{{ page.date | date(format=config.extra.date_format | default (value="%d %B %Y")) }}</span>
{{ separator }}
{% endif %}
@ -30,7 +30,7 @@
{% endif %}
{% if page.updated %}
<br><span>Last updated on {{ macros_format_date::format_date(date=page.updated) }}</span>
<br><span>Last updated on {{ page.updated | date(format=config.extra.date_format | default (value="%d %B %Y")) }}</span>
{% endif %}
</ul>

@ -1,22 +0,0 @@
{% macro format_date(date) %}
{% if config.extra.date_format %}
{{ date | date(format=config.extra.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 %}
{{ date | date(format="%-d") }}{{ suffix }} {{ date | date(format="%B %Y") }}
{% endif %}
{% endmacro %}

@ -13,7 +13,7 @@
{% if post.date %}
<div class="date">
{{ macros_format_date::format_date(date=post.date) }}
{{ post.date | date(format=config.extra.date_format | default (value="%d %B %Y")) }}
</div>
{% endif %}

Loading…
Cancel
Save