Changes
7 changed files (+54/-16)
-
-
@@ -22,7 +22,7 @@ buildGoModule {]; }; vendorHash = "sha256-SWMJVv7QQt4gHaPjb5Q5m20jzFMPHqa+McI26EYg6Ak="; vendorHash = "sha256-48A57dojm6J5ONfbA5N9AfLCIPV0T4v3U2RaCRKZsmY="; ldflags = [ # git binary from nixpkgs links against libs under "/nix/store/.../lib"
-
-
-
@@ -12,6 +12,7 @@// - "datetime" ... displays date and time (default) // - "date" ... displays date // - "time" ... displays time // - "relative" ... displays relative datetime (e.g. 3 days ago) // // This script intentionally uses scratch serialization instead of locale-aware // APIs; locale strings often includes non-English characters thus does not
-
@@ -19,6 +20,13 @@// softwares, using RFC3339-ish style date and time format fits better than an // uncontrollable locale string. const MS_PER_MIN = 60 * 1000; const MS_PER_HOUR = MS_PER_MIN * 60; const MS_PER_DAY = MS_PER_HOUR * 24; const MS_PER_WEEK = MS_PER_DAY * 7; const MS_PER_MONTH = MS_PER_DAY * 30; const MS_PER_YEAR = MS_PER_MONTH * 12; function toTimeString(date) { return date.getHours().toString().padStart(2, "0") + ":" + date.getMinutes().toString().padStart(2, "0") + ":"
-
@@ -37,6 +45,41 @@ function toDateTimeString(date) {return toDateString(date) + " " + toTimeString(date); } function toRelativeDatetimeString(date, now = Date.now()) { if (typeof Intl.RelativeTimeFormat !== "function") { return toDateTimeString(date); } const formatter = new Intl.RelativeTimeFormat(document.documentElement.lang); const delta = now - date.valueOf(); if (delta < MS_PER_MIN) { return formatter.format(-Math.floor(delta / 1000), "second"); } if (delta < MS_PER_HOUR) { return formatter.format(-Math.floor(delta / MS_PER_MIN), "minute"); } if (delta < MS_PER_DAY) { return formatter.format(-Math.floor(delta / MS_PER_HOUR), "hour"); } if (delta < MS_PER_WEEK) { return formatter.format(-Math.floor(delta / MS_PER_DAY), "day"); } if (delta < MS_PER_MONTH) { return formatter.format(-Math.floor(delta / MS_PER_WEEK), "week"); } if (delta < MS_PER_YEAR) { return formatter.format(-Math.floor(delta / MS_PER_MONTH), "month"); } return formatter.format(-Math.floor(delta / MS_PER_YEAR), "year"); } const targets = document.querySelectorAll("time[data-local-format]"); for (const target of targets) { const datetime = target.dateTime && Date.parse(target.dateTime);
-
@@ -56,6 +99,9 @@ for (const target of targets) {case "time": target.textContent = toTimeString(new Date(datetime)); break; case "relative": target.textContent = toRelativeDatetimeString(new Date(datetime)); break; default: console.warn( `Found unknown value on data-local-format attribute: "${target.dataset.localFormat}".\n`
-
-
-
@@ -12,6 +12,7 @@ SPDX-License-Identifier: MIT{{- if .Config.Meta.Description }} <meta name="description" content="{{ .Config.Meta.Description }}" /> {{- end }} <script type="module" src="/static/convert-to-local-datetime.js"></script> </head> <body> <header class="header">
-
@@ -35,9 +36,9 @@ SPDX-License-Identifier: MITUpdated <time datetime='{{ .LastCommit.Committer.When.Format "2006-01-02T15:04:05-0700" }}' title='{{ .LastCommit.Committer.When.Format "2006-01-02 15:04:05 -0700" }}' data-local-format="relative" > {{- .LastCommitAtRelative -}} at {{ .LastCommit.Committer.When.Format "2006-01-02 15:04:05 -0700" -}} </time> </span> </a>
-
-
-
@@ -6,7 +6,6 @@ require (github.com/alecthomas/chroma/v2 v2.27.0 github.com/bluekeyes/go-gitdiff v0.8.0 github.com/cyphar/filepath-securejoin v0.4.1 github.com/dustin/go-humanize v1.0.1 github.com/go-git/go-billy/v5 v5.6.2 github.com/go-git/go-git/v5 v5.13.2 github.com/landlock-lsm/go-landlock v0.9.0
-
-
-
@@ -28,8 +28,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97cgithub.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dlclark/regexp2/v2 v2.2.1 h1:mf4KkFUj0gJuarK8P+LgiS+Lit7m9N1yAwEfPbee7R0= github.com/dlclark/regexp2/v2 v2.2.1/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/elazarl/goproxy v1.4.0 h1:4GyuSbFa+s26+3rmYNSuUVsx+HgPrV1bk1jXI0l9wjM= github.com/elazarl/goproxy v1.4.0/go.mod h1:X/5W/t+gzDyLfHW4DrMdpjqYjpXsURlBt9lpBDxZZZQ= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
-
-
-
@@ -25,10 +25,6 @@ type repositorySummary struct {// Description is a contents of "description" text file in the repository root. Description string // LastCommitAtRelative is a relative datetime string of last commit. // For example, "1 hour ago" or "2 years ago". LastCommitAtRelative string LastCommit *object.Commit }
-
-
-
@@ -13,7 +13,6 @@ import ("strings" securejoin "github.com/cyphar/filepath-securejoin" "github.com/dustin/go-humanize" "github.com/go-git/go-git/v5/plumbing" "github.com/pocka/legit/config" "github.com/pocka/legit/git"
-
@@ -74,11 +73,10 @@ func (d *deps) Index(w http.ResponseWriter, r *http.Request) {} summaries = append(summaries, repositorySummary{ DisplayName: getDisplayName(name), DirName: name, Description: getDescription(path), LastCommitAtRelative: humanize.Time(c.Committer.When), LastCommit: c, DisplayName: getDisplayName(name), DirName: name, Description: getDescription(path), LastCommit: c, }) }
-