From 4b18391c188c0b55e8a76a1297ea96f0aa4531d9 Mon Sep 17 00:00:00 2001 From: welpo Date: Mon, 6 Mar 2023 00:07:41 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20format=20date?= =?UTF-8?q?=20as=20"6=20July=202049"=20Follows=20Oxford's=20and=20other=20?= =?UTF-8?q?formal=20style=20manuals.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.toml | 4 +--- templates/base.html | 1 - templates/macros/cards_posts.html | 2 +- templates/macros/content.html | 4 ++-- templates/macros/format_date.html | 22 ---------------------- templates/macros/list_posts.html | 2 +- 6 files changed, 5 insertions(+), 30 deletions(-) delete mode 100644 templates/macros/format_date.html diff --git a/config.toml b/config.toml index 8b2d44b..7157a27 100644 --- a/config.toml +++ b/config.toml @@ -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 = "•" diff --git a/templates/base.html b/templates/base.html index dee73e3..7cec6b3 100644 --- a/templates/base.html +++ b/templates/base.html @@ -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 %} diff --git a/templates/macros/cards_posts.html b/templates/macros/cards_posts.html index 43d2cf7..dc6907b 100644 --- a/templates/macros/cards_posts.html +++ b/templates/macros/cards_posts.html @@ -21,7 +21,7 @@
{%- 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 %} DRAFT diff --git a/templates/macros/content.html b/templates/macros/content.html index e29ef2e..0c8c1bf 100644 --- a/templates/macros/content.html +++ b/templates/macros/content.html @@ -13,7 +13,7 @@ {% endif %} {% if page.date %} - {{ macros_format_date::format_date(date=page.date) }} + {{ page.date | date(format=config.extra.date_format | default (value="%d %B %Y")) }} {{ separator }} {% endif %} @@ -30,7 +30,7 @@ {% endif %} {% if page.updated %} -
Last updated on {{ macros_format_date::format_date(date=page.updated) }} +
Last updated on {{ page.updated | date(format=config.extra.date_format | default (value="%d %B %Y")) }} {% endif %} diff --git a/templates/macros/format_date.html b/templates/macros/format_date.html deleted file mode 100644 index 33f930e..0000000 --- a/templates/macros/format_date.html +++ /dev/null @@ -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 %} diff --git a/templates/macros/list_posts.html b/templates/macros/list_posts.html index b816fa7..e10f52f 100644 --- a/templates/macros/list_posts.html +++ b/templates/macros/list_posts.html @@ -13,7 +13,7 @@ {% if post.date %}
- {{ macros_format_date::format_date(date=post.date) }} + {{ post.date | date(format=config.extra.date_format | default (value="%d %B %Y")) }}
{% endif %}