Skip to content
Browse files

Fix date-based post header links

Posts without an explicit title render the date as the post header in
lists of posts (like on the blog index and tag pages). This updates
localdate.js to properly adjust those dates, too.
  • Loading branch information
thebaer committed Jan 29, 2020
1 parent 3e90246 commit 4d5f58a7e65733f1fe6e4c8819708abdfcc295cd
Showing with 12 additions and 5 deletions.
  1. +12 −5 static/js/localdate.js
@@ -1,9 +1,16 @@
function toLocalDate(el) {
var d = new Date(el.getAttribute("datetime"));
el.textContent = d.toLocaleDateString(navigator.language || "en-US", { year: 'numeric', month: 'long', day: 'numeric' });
function toLocalDate(dateEl, displayEl) {
var d = new Date(dateEl.getAttribute("datetime"));
displayEl.textContent = d.toLocaleDateString(navigator.language || "en-US", { year: 'numeric', month: 'long', day: 'numeric' });

var $dates = document.querySelectorAll("time");
// Adjust dates on individual post pages, and on posts in a list *with* an explicit title
var $dates = document.querySelectorAll("article > time");
for (var i=0; i < $dates.length; i++) {
toLocalDate($dates[i], $dates[i]);

// Adjust dates on posts in a list without an explicit title, where they act as the header
$dates = document.querySelectorAll(" > time");
for (i=0; i < $dates.length; i++) {
toLocalDate($dates[i], $dates[i].querySelector('a'));

0 comments on commit 4d5f58a

Please sign in to comment.
You can’t perform that action at this time.