From 0ecc6eff7846f7d29f7f1e76e25c0baeba4a1568 Mon Sep 17 00:00:00 2001 From: welpo Date: Sun, 19 Feb 2023 02:27:01 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20use=20ordinal=20day=20numbe?= =?UTF-8?q?r=20in=20dates=20If=20the=20date=5Fformat=20variable=20in=20con?= =?UTF-8?q?fig.toml=20is=20empty,=20the=20new=20format=20date=20will=20be?= =?UTF-8?q?=20used.=20Example:=202nd=20August=202043.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.toml | 2 +- templates/macros/macros.html | 33 +++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/config.toml b/config.toml index 3397940..7d6f480 100644 --- a/config.toml +++ b/config.toml @@ -17,7 +17,7 @@ highlight_theme = "css" [extra] use_cdn = false -timeformat = "%d %B %Y" # Default format: "31 January 2049" +date_format = "" # If unset, uses format: "1st January 2049" #Full path after the base URL required. So if you were to place it in "static" it would be "/favicon.ico" favicon = "" diff --git a/templates/macros/macros.html b/templates/macros/macros.html index f20d227..19d86cf 100644 --- a/templates/macros/macros.html +++ b/templates/macros/macros.html @@ -1,3 +1,27 @@ +{% macro format_date(date) %} + {% if config.extra.date_format %} + {{ date | date(format=config.extra.date_format) }} + {% else %} + {% set day = date | date(format='%-d') | int %} + {% set suffix = "" %} + {% 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 %} + {% macro list_posts(pages) %}
{%- for page in pages %} @@ -8,7 +32,7 @@
{%- if page.date %} - {{ page.date | date(format=config.extra.timeformat) }} + {{ post_macros::format_date(date=page.date, format=config.extra.date_format) }} {% endif -%}
{{ page.reading_time }} minute read @@ -91,7 +115,8 @@ {% endif %} {% if page.date %} - {{ page.date | date(format=config.extra.timeformat) }} • + {{ post_macros::format_date(date=page.date) }} + • {% endif %} {{ page.reading_time }} minute read{% if page.taxonomies and page.taxonomies.tags %} {% @@ -180,7 +205,7 @@
{%- if page.date %} - {{ page.date | date(format=config.extra.timeformat) }} + {{ post_macros::format_date(date=page.date) }} {% endif -%} {% if page.draft %} DRAFT @@ -210,7 +235,7 @@ {% for page in pages %}
  • {{ page.title }} - {{ page.date | date(format=config.extra.timeformat) }} + {{ post_macros::format_date(date=page.date) }}
  • {% endfor %}