From 07b85f19ece1db8baecc7b81c1a18e08e2886145 Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Fri, 10 Mar 2023 16:24:44 +0100 Subject: [PATCH] Auto-adjust publish and update timestamps via JS --- static/scripts/relativetime.js | 10 ++++++++++ templates/page.html | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 static/scripts/relativetime.js diff --git a/static/scripts/relativetime.js b/static/scripts/relativetime.js new file mode 100644 index 0000000..cc7cad6 --- /dev/null +++ b/static/scripts/relativetime.js @@ -0,0 +1,10 @@ +"use strict"; + +Array.from(document.getElementsByClassName("relative-timestamp")).forEach( + function (timestamp) { + timestamp.innerText = new Intl.DateTimeFormat(undefined, { + dateStyle: "long", + timeStyle: "short", + }).format(new Date(timestamp.dateTime)); + } +); diff --git a/templates/page.html b/templates/page.html index 1352a52..a9fa884 100644 --- a/templates/page.html +++ b/templates/page.html @@ -1,6 +1,7 @@ {% extends "base.html" %} {% block metadata %} + {% endblock %} {% block content %}

{{ page.title }}

@@ -8,7 +9,7 @@ {% if page.date and page.date is defined %}

: - @@ -16,7 +17,7 @@ {% endif %} {% if page.updated and page.updated != page.date %}

: -