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
This commit is contained in:
Rob Loranger 2019-10-03 09:47:08 -07:00
parent 3759f16ed3
commit caca8f0ae2
No known key found for this signature in database
GPG Key ID: D6F1633A4F0903B8
4 changed files with 12 additions and 0 deletions

9
static/js/localdate.js Normal file
View File

@ -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]);
}

View File

@ -90,6 +90,7 @@ article time.dt-published {
{{range .Collection.ExternalScripts}}<script type="text/javascript" src="{{.}}" async></script>{{end}}
{{if .Collection.Script}}<script type="text/javascript">{{.Collection.ScriptDisplay}}</script>{{end}}
{{end}}
<script src="/js/localdate.js"></script>
<script type="text/javascript">
var pinning = false;

View File

@ -70,6 +70,7 @@
{{range .Collection.ExternalScripts}}<script type="text/javascript" src="{{.}}" async></script>{{end}}
{{if .Collection.Script}}<script type="text/javascript">{{.Collection.ScriptDisplay}}</script>{{end}}
{{end}}
<script src="/js/localdate.js"></script>
<script type="text/javascript">
var pinning = false;

View File

@ -113,6 +113,7 @@
{{end}}
<script src="/js/h.js"></script>
<script src="/js/postactions.js"></script>
<script src="/js/localdate.js"></script>
<script type="text/javascript">
var deleting = false;
function delPost(e, id, owned) {