Changes
4 changed files (+92/-5)
-
-
@@ -0,0 +1,69 @@// Copyright 2025 Shota FUJI <pockawoooh@gmail.com> // SPDX-License-Identifier: MIT // // === // // This script scans every "<time>" elements with "data-local-format" attribute, // replaces each element's text node with local datetime. // If a "<time>" element does not have valid "datetime" attribute, this script // skips the "<time>" element. // // "data-local-format" attribute accepts one of the below: // - "datetime" ... displays date and time (default) // - "date" ... displays date // - "time" ... displays time // // This script intentionally uses scratch serialization instead of locale-aware // APIs; locale strings often includes non-English characters thus does not // incorporate with the rest of a page. As majority of readers are familiar with // softwares, using RFC3339-ish style date and time format fits better than an // uncontrollable locale string. function toTimeString(date) { return date.getHours().toString().padStart(2, "0") + ":" + date.getMinutes().toString().padStart(2, "0") + ":" + date.getSeconds().toString().padStart(2, "0"); } function toDateString(date) { // I don't expect this software/code will survive for 8000yrs. return date.getFullYear().toString().padStart(4, "0") + "-" // stupid spec made by American + (date.getMonth() + 1).toString().padStart(2, "0") + "-" + date.getDate().toString().padStart(2, "0"); } function toDateTimeString(date) { return toDateString(date) + " " + toTimeString(date); } const targets = document.querySelectorAll("time[data-local-format]"); for (const target of targets) { const datetime = target.dateTime && Date.parse(target.dateTime); if (Number.isNaN(datetime)) { continue; } const originalText = target.textContent.trim(); switch (target.dataset.localFormat || "datetime") { case "datetime": target.textContent = toDateTimeString(new Date(datetime)); break; case "date": target.textContent = toDateString(new Date(datetime)); break; case "time": target.textContent = toTimeString(new Date(datetime)); break; default: console.warn( `Found unknown value on data-local-format attribute: "${target.dataset.localFormat}".\n` + `Available values are: "datetime", "date", "time"\n` + "Skipping text replacement.", ); break; } target.title = originalText; }
-
-
-
@@ -13,6 +13,7 @@ <title>{{ $shorthash }} - {{ .Meta.DisplayName }} </title> <meta name="description" content='{{ $shorthash }} in {{ .Meta.DisplayName }}' /> <script type="module" src="/static/convert-to-local-datetime.js"></script> </head> <body> <header class="header">
-
@@ -108,7 +109,10 @@ </a></dd> <dt class="metadata--key">Authored at</dt> <dd class="metadata--value"> <time datetime='{{ .Commit.Author.When.Format "2006-01-02T15:04:05-0700" }}'> <time datetime='{{ .Commit.Author.When.Format "2006-01-02T15:04:05-0700" }}' data-local-format="" > {{ .Commit.Author.When.Format "2006-01-02 15:04:05 -0700" }} </time> </dd>
-
@@ -120,7 +124,10 @@ </a></dd> <dt class="metadata--key">Committed at</dt> <dd class="metadata--value"> <time datetime='{{ .Commit.Committer.When.Format "2006-01-02T15:04:05-0700" }}'> <time datetime='{{ .Commit.Committer.When.Format "2006-01-02T15:04:05-0700" }}' data-local-format="" > {{ .Commit.Committer.When.Format "2006-01-02 15:04:05 -0700" }} </time> </dd>
-
-
-
@@ -12,6 +12,7 @@ <title>Commit history at {{ .Meta.Ref }} - {{ .Meta.DisplayName }} </title> <meta name="description" content='Commit history on {{ .Meta.DisplayName }} at {{ .Meta.Ref }}' /> <script type="module" src="/static/convert-to-local-datetime.js"></script> </head> <body> <header class="header">
-
@@ -48,7 +49,10 @@ <a href="mailto:{{ .Author.Email }}">{{- .Author.Name -}} </a> authored at <time datetime='{{ .Author.When.Format "2006-01-02T15:04:05-0700" }}'> <time datetime='{{ .Author.When.Format "2006-01-02T15:04:05-0700" }}' data-local-format="" > {{ .Author.When.Format "2006-01-02 15:04:05 -0700" }} </time> </span>
-
@@ -57,7 +61,10 @@ <a href="mailto:{{ .Committer.Email }}">{{- .Committer.Name -}} </a> comitted at <time datetime='{{ .Committer.When.Format "2006-01-02T15:04:05-0700" }}'> <time datetime='{{ .Committer.When.Format "2006-01-02T15:04:05-0700" }}' data-local-format="" > {{ .Committer.When.Format "2006-01-02 15:04:05 -0700" }} </time> </span>
-
-
-
@@ -12,6 +12,7 @@ <title>{{ .Meta.DisplayName }} | {{ .Config.Meta.Title }}</title>{{- if .Meta.Description }} <meta name="description" content="{{ .Meta.Description }}" /> {{- end }} <script type="module" src="/static/convert-to-local-datetime.js"></script> </head> <body> <header class="header">
-
@@ -60,7 +61,10 @@ <a href="mailto:{{ .Committer.Email }}">{{- .Committer.Name -}} </a> comitted at <time datetime='{{ .Committer.When.Format "2006-01-02T15:04:05-0700" }}'> <time datetime='{{ .Committer.When.Format "2006-01-02T15:04:05-0700" }}' data-local-format="" > {{ .Committer.When.Format "2006-01-02 15:04:05 -0700" }} </time> </span>
-