From cd1eaca903e1996e2da87b71087217053c85294b Mon Sep 17 00:00:00 2001
From: uncenter
Date: Sat, 12 Jul 2025 17:11:21 -0400
Subject: [PATCH] appview/pages: use consistent time component
Creates a new template fragment, repo/fragments/time, that is a component based on the HTML element. The element is already used for most datetimes, but inconsistently; some define `title` attributes and/or `datetime` attributes, most don't. The goal here is to standardize with a single component so every date has a consistent interaction. The datetime is ISO 8601 formatted as per the spec, the `title` (shown on hover) is a modified long format similar to GitHub's, and the content is a relative format %s ago (`timeFmt` - two `shortTimeFmt` variants also exist to preserve existing behavior).
---
appview/pages/funcmap.go | 5 ++++-
appview/pages/templates/knot.html | 4 ++--
appview/pages/templates/knots.html | 4 ++--
appview/pages/templates/repo/branches.html | 4 ++--
appview/pages/templates/repo/commit.html | 2 +-
appview/pages/templates/repo/compare/new.html | 2 +-
appview/pages/templates/repo/empty.html | 2 +-
.../pages/templates/repo/fragments/artifact.html | 4 ++--
appview/pages/templates/repo/fragments/time.html | 15 +++++++++++++++
appview/pages/templates/repo/index.html | 14 +++++---------
.../repo/issues/fragments/editIssueComment.html | 2 +-
.../repo/issues/fragments/issueComment.html | 6 +++---
appview/pages/templates/repo/issues/issue.html | 4 +---
appview/pages/templates/repo/issues/issues.html | 4 +---
appview/pages/templates/repo/log.html | 4 ++--
.../pages/templates/repo/pipelines/pipelines.html | 4 +---
.../repo/pulls/fragments/pullHeader.html | 2 +-
appview/pages/templates/repo/pulls/pull.html | 4 ++--
appview/pages/templates/repo/pulls/pulls.html | 6 ++----
appview/pages/templates/repo/tags.html | 4 ++--
appview/pages/templates/repo/tree.html | 4 ++--
appview/pages/templates/settings.html | 4 ++--
.../spindles/fragments/spindleListing.html | 4 ++--
appview/pages/templates/timeline.html | 12 ++++++------
24 files changed, 63 insertions(+), 57 deletions(-)
create mode 100644 appview/pages/templates/repo/fragments/time.html
diff --git a/appview/pages/funcmap.go b/appview/pages/funcmap.go
index abf2252..f15de80 100644
--- a/appview/pages/funcmap.go
+++ b/appview/pages/funcmap.go
@@ -107,7 +107,10 @@ func (p *Pages) funcMap() template.FuncMap {
},
"timeFmt": humanize.Time,
"longTimeFmt": func(t time.Time) string {
- return t.Format("2006-01-02 * 3:04 PM")
+ return t.Format("Jan 2, 2006, 3:04 PM MST")
+ },
+ "iso8601Fmt": func(t time.Time) string {
+ return t.Format("2006-01-02T15:04:05-07:00")
},
"commaFmt": humanize.Comma,
"shortTimeFmt": func(t time.Time) string {
diff --git a/appview/pages/templates/knot.html b/appview/pages/templates/knot.html
index 46c6231..37782ed 100644
--- a/appview/pages/templates/knot.html
+++ b/appview/pages/templates/knot.html
@@ -26,11 +26,11 @@
opened
- {{ .Registration.Created | timeFmt }}
+ {{ template "repo/fragments/time" .Registration.Created }}
{{ if .Registration.Registered }}
registered
- {{ .Registration.Registered | timeFmt }}
+ {{ template "repo/fragments/time" .Registration.Registered }}
{{ else }}
status
diff --git a/appview/pages/templates/knots.html b/appview/pages/templates/knots.html
index 3a21bf9..2509555 100644
--- a/appview/pages/templates/knots.html
+++ b/appview/pages/templates/knots.html
@@ -44,7 +44,7 @@
owned by {{ .ByDid }}
- registered {{ .Registered | timeFmt }}
+ registered {{ template "repo/fragments/time" .Registered }}
{{ end }}
@@ -70,7 +70,7 @@
opened by {{ .ByDid }}
- created {{ .Created | timeFmt }}
+ created {{ template "repo/fragments/time" .Created }}
{{ if .Commit }}
- {{ .Commit.Committer.When | timeFmt }}
+ {{ template "repo/fragments/time" .Commit.Committer.When }}
{{ end }}
@@ -98,7 +98,7 @@
- {{ .Commit.Committer.When | timeFmt }}
+ {{ template "repo/fragments/time" .Commit.Committer.When }}
{{ end }}
diff --git a/appview/pages/templates/repo/commit.html b/appview/pages/templates/repo/commit.html
index 8eaab8e..0b341da 100644
--- a/appview/pages/templates/repo/commit.html
+++ b/appview/pages/templates/repo/commit.html
@@ -34,7 +34,7 @@
{{ $commit.Author.Name }}
{{ end }}
- {{ timeFmt $commit.Author.When }}
+ {{ template "repo/fragments/time" $commit.Author.When }}
diff --git a/appview/pages/templates/repo/compare/new.html b/appview/pages/templates/repo/compare/new.html
index 5055aab..a501984 100644
--- a/appview/pages/templates/repo/compare/new.html
+++ b/appview/pages/templates/repo/compare/new.html
@@ -19,7 +19,7 @@
{{ $br.Name }}
-
{{ timeFmt $br.Commit.Committer.When }}
+
{{ template "repo/fragments/time" $br.Commit.Committer.When }}
{{ end }}
diff --git a/appview/pages/templates/repo/empty.html b/appview/pages/templates/repo/empty.html
index 639df80..54cb8ee 100644
--- a/appview/pages/templates/repo/empty.html
+++ b/appview/pages/templates/repo/empty.html
@@ -17,7 +17,7 @@
{{ $br.Name }}
-
{{ timeFmt $br.Commit.Committer.When }}
+
{{ template "repo/fragments/time" $br.Commit.Committer.When }}
{{ end }}
diff --git a/appview/pages/templates/repo/fragments/artifact.html b/appview/pages/templates/repo/fragments/artifact.html
index bf8849d..b4d98b7 100644
--- a/appview/pages/templates/repo/fragments/artifact.html
+++ b/appview/pages/templates/repo/fragments/artifact.html
@@ -10,8 +10,8 @@
-
{{ timeFmt .Artifact.CreatedAt }}
-
{{ shortTimeFmt .Artifact.CreatedAt }}
+
{{ template "repo/fragments/time" .Artifact.CreatedAt }}
+
{{ template "repo/fragments/shortTime" .Artifact.CreatedAt }}
{{ .Artifact.MimeType }}
diff --git a/appview/pages/templates/repo/fragments/time.html b/appview/pages/templates/repo/fragments/time.html
new file mode 100644
index 0000000..7934f81
--- /dev/null
+++ b/appview/pages/templates/repo/fragments/time.html
@@ -0,0 +1,15 @@
+{{ define "repo/fragments/timeWrapper" }}
+
{{ .Content }}
+{{ end }}
+
+{{ define "repo/fragments/time" }}
+{{ template "repo/fragments/timeWrapper" (dict "Time" . "Content" (. | timeFmt)) }}
+{{ end }}
+
+{{ define "repo/fragments/shortTime" }}
+{{ template "repo/fragments/timeWrapper" (dict "Time" . "Content" (. | shortTimeFmt)) }}
+{{ end }}
+
+{{ define "repo/fragments/shortTimeAgo" }}
+{{ template "repo/fragments/timeWrapper" (dict "Time" . "Content" (print (. | shortTimeFmt) " ago")) }}
+{{ end }}
\ No newline at end of file
diff --git a/appview/pages/templates/repo/index.html b/appview/pages/templates/repo/index.html
index 55e5abd..7081f14 100644
--- a/appview/pages/templates/repo/index.html
+++ b/appview/pages/templates/repo/index.html
@@ -149,9 +149,7 @@
{{ if .LastCommit }}
-
{{ timeFmt .LastCommit.When }}
+
{{ template "repo/fragments/time" .LastCommit.When }}
{{ end }}
@@ -172,9 +170,7 @@
{{ if .LastCommit }}
- {{ timeFmt .LastCommit.When }}
+ {{ template "repo/fragments/time" .LastCommit.When }}
{{ end }}
@@ -273,7 +269,7 @@
>
- {{ timeFmt .Committer.When }}
+ {{ template "repo/fragments/time" .Committer.When }}
{{ $tagsForCommit := index $.TagMap .Hash.String }}
@@ -320,7 +316,7 @@
{{ if .Commit }}
- {{ timeFmt .Commit.Committer.When }}
+ {{ template "repo/fragments/time" .Commit.Committer.When }}
{{ end }}
{{ if .IsDefault }}
@@ -366,7 +362,7 @@
{{ with .Tag }}
-
{{ timeFmt .Tagger.When }}
+
{{ template "repo/fragments/time" .Tagger.When }}
{{ end }}
{{ if eq $idx 0 }}
{{ with .Tag }}
{{ end }}
diff --git a/appview/pages/templates/repo/issues/fragments/editIssueComment.html b/appview/pages/templates/repo/issues/fragments/editIssueComment.html
index ce6aac3..64082f4 100644
--- a/appview/pages/templates/repo/issues/fragments/editIssueComment.html
+++ b/appview/pages/templates/repo/issues/fragments/editIssueComment.html
@@ -19,7 +19,7 @@
href="#{{ .CommentId }}"
class="text-gray-500 hover:text-gray-500 hover:underline no-underline"
id="{{ .CommentId }}">
- {{ .Created | timeFmt }}
+ {{ template "repo/fragments/time" .Created }}
diff --git a/appview/pages/templates/repo/issues/issues.html b/appview/pages/templates/repo/issues/issues.html
index 1501159..21aede5 100644
--- a/appview/pages/templates/repo/issues/issues.html
+++ b/appview/pages/templates/repo/issues/issues.html
@@ -70,9 +70,7 @@
-
- {{ .Created | timeFmt }}
-
+ {{ template "repo/fragments/time" .Created }}
diff --git a/appview/pages/templates/repo/log.html b/appview/pages/templates/repo/log.html
index 793cb4a..f0fb1e3 100644
--- a/appview/pages/templates/repo/log.html
+++ b/appview/pages/templates/repo/log.html
@@ -87,7 +87,7 @@
{{ template "repo/pipelines/fragments/pipelineSymbolLong" (dict "Pipeline" $pipeline "RepoInfo" $.RepoInfo) }}
{{ end }}
- {{ timeFmt $commit.Committer.When }}
+ {{ template "repo/fragments/time" $commit.Committer.When }}
{{ end }}
@@ -163,7 +163,7 @@
- {{ shortTimeFmt $commit.Committer.When }}
+ {{ template "repo/fragments/shortTime" $commit.Committer.When }}
{{ $pipeline := index $.Pipelines .Hash.String }}
diff --git a/appview/pages/templates/repo/pipelines/pipelines.html b/appview/pages/templates/repo/pipelines/pipelines.html
index 0d06538..457c189 100644
--- a/appview/pages/templates/repo/pipelines/pipelines.html
+++ b/appview/pages/templates/repo/pipelines/pipelines.html
@@ -74,9 +74,7 @@
-
- {{ .Created | shortTimeFmt }} ago
-
+ {{ template "repo/fragments/shortTimeAgo" .Created }}
{{ $t := .TimeTaken }}
diff --git a/appview/pages/templates/repo/pulls/fragments/pullHeader.html b/appview/pages/templates/repo/pulls/fragments/pullHeader.html
index 24cb25a..c3a67c0 100644
--- a/appview/pages/templates/repo/pulls/fragments/pullHeader.html
+++ b/appview/pages/templates/repo/pulls/fragments/pullHeader.html
@@ -31,7 +31,7 @@
{{ $owner := index $.DidHandleMap .Pull.OwnerDid }}
{{ template "user/fragments/picHandle" $owner }}
- {{ .Pull.Created | timeFmt }}
+ {{ template "repo/fragments/time" .Pull.Created }}
diff --git a/appview/pages/templates/repo/pulls/pull.html b/appview/pages/templates/repo/pulls/pull.html
index 16d1084..0023358 100644
--- a/appview/pages/templates/repo/pulls/pull.html
+++ b/appview/pages/templates/repo/pulls/pull.html
@@ -55,7 +55,7 @@
{{$re}}submitted
by {{ $owner }}
- {{ .Created | shortTimeFmt }}
+ {{ template "repo/fragments/shortTime" .Created }}
{{ $s := "s" }}
{{ if eq (len .Comments) 1 }}
@@ -154,7 +154,7 @@
{{ $owner := index $.DidHandleMap $c.OwnerDid }}
{{$owner}}
- {{ $c.Created | shortTimeFmt }}
+ {{ template "repo/fragments/time" $c.Created }}
{{ $c.Body | markdown }}
diff --git a/appview/pages/templates/repo/pulls/pulls.html b/appview/pages/templates/repo/pulls/pulls.html
index 2c46070..f4c9dbf 100644
--- a/appview/pages/templates/repo/pulls/pulls.html
+++ b/appview/pages/templates/repo/pulls/pulls.html
@@ -79,10 +79,8 @@
{{ template "user/fragments/picHandle" $owner }}
-
-
- {{ .Created | timeFmt }}
-
+
+ {{ template "repo/fragments/time" .Created }}
diff --git a/appview/pages/templates/repo/tags.html b/appview/pages/templates/repo/tags.html
index a17d05f..2fe3fa1 100644
--- a/appview/pages/templates/repo/tags.html
+++ b/appview/pages/templates/repo/tags.html
@@ -35,7 +35,7 @@
{{ .Tag.Tagger.Name }}
- {{ shortTimeFmt .Tag.Tagger.When }}
+ {{ template "repo/fragments/shortTime" .Tag.Tagger.When }}
{{ end }}
@@ -54,7 +54,7 @@
{{ slice .Tag.Target.String 0 8 }}
{{ .Tag.Tagger.Name }}
- {{ timeFmt .Tag.Tagger.When }}
+ {{ template "repo/fragments/time" .Tag.Tagger.When }}
{{ end }}
diff --git a/appview/pages/templates/repo/tree.html b/appview/pages/templates/repo/tree.html
index 6dcbb36..12af682 100644
--- a/appview/pages/templates/repo/tree.html
+++ b/appview/pages/templates/repo/tree.html
@@ -63,7 +63,7 @@
{{ if .LastCommit}}
- {{ timeFmt .LastCommit.When }}
+ {{ template "repo/fragments/time" .LastCommit.When }}
{{ end }}
@@ -80,7 +80,7 @@
{{ if .LastCommit}}
- {{ timeFmt .LastCommit.When }}
+ {{ template "repo/fragments/time" .LastCommit.When }}
{{ end }}
diff --git a/appview/pages/templates/settings.html b/appview/pages/templates/settings.html
index 1405791..8a1979b 100644
--- a/appview/pages/templates/settings.html
+++ b/appview/pages/templates/settings.html
@@ -39,7 +39,7 @@
{{ i "key" "w-3 h-3 dark:text-gray-300" }}
{{ .Name }}
- added {{ .Created | timeFmt }}
+ added {{ template "repo/fragments/time" .Created }}
{{ .Key }}
@@ -112,7 +112,7 @@
{{ end }}
- added {{ .CreatedAt | timeFmt }}
+ added {{ template "repo/fragments/time" .CreatedAt }}
{{ if not .Verified }}
diff --git a/appview/pages/templates/spindles/fragments/spindleListing.html b/appview/pages/templates/spindles/fragments/spindleListing.html
index 71a5e73..56ae1e0 100644
--- a/appview/pages/templates/spindles/fragments/spindleListing.html
+++ b/appview/pages/templates/spindles/fragments/spindleListing.html
@@ -11,7 +11,7 @@
{{ i "hard-drive" "w-4 h-4" }}
{{ .Instance }}
- {{ .Created | shortTimeFmt }} ago
+ {{ template "repo/fragments/shortTimeAgo" .Created }}
{{ else }}
@@ -19,7 +19,7 @@
{{ i "hard-drive" "w-4 h-4" }}
{{ .Instance }}
- {{ .Created | shortTimeFmt }} ago
+ {{ template "repo/fragments/shortTimeAgo" .Created }}
{{ end }}
diff --git a/appview/pages/templates/timeline.html b/appview/pages/templates/timeline.html
index 02cba48..4ecadc1 100644
--- a/appview/pages/templates/timeline.html
+++ b/appview/pages/templates/timeline.html
@@ -84,9 +84,9 @@
>{{ .Repo.Name }}
{{ end }}
- {{ .Repo.Created | timeFmt }} {{ template "repo/fragments/time" .Repo.Created }}
@@ -98,9 +98,9 @@
{{ template "user/fragments/picHandle" $userHandle }}
followed
{{ template "user/fragments/picHandle" $subjectHandle }}
- {{ .Follow.FollowedAt | timeFmt }} {{ template "repo/fragments/time" .Follow.FollowedAt }}
@@ -116,9 +116,9 @@
class="no-underline hover:underline"
>{{ $repoOwnerHandle | truncateAt30 }}/{{ .Star.Repo.Name }}
- {{ .Star.Created | timeFmt }} {{ template "repo/fragments/time" .Star.Created }}
--
2.43.0