mirror of https://github.com/writeas/writefreely
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.pull/191/head
parent
3e902461f1
commit
4d5f58a7e6
@ -1,9 +1,16 @@ |
|||||||
function toLocalDate(el) { |
function toLocalDate(dateEl, displayEl) { |
||||||
var d = new Date(el.getAttribute("datetime")); |
var d = new Date(dateEl.getAttribute("datetime")); |
||||||
el.textContent = d.toLocaleDateString(navigator.language || "en-US", { year: 'numeric', month: 'long', day: 'numeric' }); |
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++) { |
for (var i=0; i < $dates.length; i++) { |
||||||
toLocalDate($dates[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("h2.post-title > time"); |
||||||
|
for (i=0; i < $dates.length; i++) { |
||||||
|
toLocalDate($dates[i], $dates[i].querySelector('a')); |
||||||
} |
} |
Loading…
Reference in new issue