From caca8f0ae26f586e4736eeefd01eef0e6ed80808 Mon Sep 17 00:00:00 2001 From: Rob Loranger Date: Thu, 3 Oct 2019 09:47:08 -0700 Subject: [PATCH 1/3] show timestamps in local date/locale this adds a helper script to rewrite all time elements with a proper datetime attribute into the users locale via the browser navigator.language. collection, collection-post and chorus-collection-post templates now include this script --- static/js/localdate.js | 9 +++++++++ templates/chorus-collection-post.tmpl | 1 + templates/collection-post.tmpl | 1 + templates/collection.tmpl | 1 + 4 files changed, 12 insertions(+) create mode 100644 static/js/localdate.js diff --git a/static/js/localdate.js b/static/js/localdate.js new file mode 100644 index 0000000..19fa502 --- /dev/null +++ b/static/js/localdate.js @@ -0,0 +1,9 @@ +function toLocalDate(el) { + var d = new Date(el.getAttribute("datetime")); + el.textContent = d.toLocaleDateString(navigator.language || "en-US", { year: 'numeric', month: 'long', day: 'numeric' }); +} + +var $dates = document.querySelectorAll("time"); +for (var i=0; i < $dates.length; i++) { + toLocalDate($dates[i]); +} diff --git a/templates/chorus-collection-post.tmpl b/templates/chorus-collection-post.tmpl index bab2e31..e60a435 100644 --- a/templates/chorus-collection-post.tmpl +++ b/templates/chorus-collection-post.tmpl @@ -90,6 +90,7 @@ article time.dt-published { {{range .Collection.ExternalScripts}}{{end}} {{if .Collection.Script}}{{end}} {{end}} + {{end}} {{if .Collection.Script}}{{end}} {{end}} + + {{end}} {{end}} + + {{end}}