From 4c9901fc035ece13b2dbaca21465a534abb77a04 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Sun, 2 Mar 2025 11:27:30 +0100 Subject: [PATCH] [chore] little frontend tweaks (#3852) * [chore] little frontend tweaks * beep boop * poke * clarify server time --- internal/router/template.go | 25 ------------------------- web/source/frontend/index.js | 24 ++++++++++++------------ web/template/profile.tmpl | 2 +- web/template/status_attributes.tmpl | 3 +-- web/template/status_info.tmpl | 4 ++-- web/template/status_poll.tmpl | 4 ++-- 6 files changed, 18 insertions(+), 44 deletions(-) diff --git a/internal/router/template.go b/internal/router/template.go index 981c3fcf4..70d87add1 100644 --- a/internal/router/template.go +++ b/internal/router/template.go @@ -26,7 +26,6 @@ "reflect" "regexp" "strings" - "time" "unsafe" "github.com/gin-gonic/gin" @@ -128,7 +127,6 @@ funcMap["includeAttr"] = func(name string, data any) (template.HTMLAttr, error) "oddOrEven": oddOrEven, "subtract": subtract, "timestampPrecise": timestampPrecise, - "timestamp": timestamp, "timestampVague": timestampVague, "visibilityIcon": visibilityIcon, } @@ -174,29 +172,6 @@ func noescapeAttr(str string) template.HTMLAttr { badTimestamp = "bad timestamp" ) -func timestamp(stamp string) string { - t, err := util.ParseISO8601(stamp) - if err != nil { - log.Errorf(nil, "error parsing timestamp %s: %s", stamp, err) - return badTimestamp - } - - t = t.Local() - - tYear, tMonth, tDay := t.Date() - now := time.Now() - currentYear, currentMonth, currentDay := now.Date() - - switch { - case tYear == currentYear && tMonth == currentMonth && tDay == currentDay: - return "Today, " + t.Format(justTime) - case tYear == currentYear: - return t.Format(dateTime) - default: - return t.Format(dateYear) - } -} - func timestampPrecise(stamp string) string { t, err := util.ParseISO8601(stamp) if err != nil { diff --git a/web/source/frontend/index.js b/web/source/frontend/index.js index 9ea10a477..310d149ed 100644 --- a/web/source/frontend/index.js +++ b/web/source/frontend/index.js @@ -182,22 +182,22 @@ Array.from(document.getElementsByClassName("plyr-video")).forEach((video) => { video._plyrContainer = player.elements.container; }); -document.addEventListener('DOMContentLoaded', () => { - const timeTags = document.getElementsByTagName('time'); - Array.from(timeTags).forEach(timeTag => { - const datetime = timeTag.getAttribute('datetime'); - const currentText = timeTag.textContent.trim(); - // Only format if current text contains precise time - if (currentText.match(/\d{2}:\d{2}/)) { - const date = new Date(datetime); - timeTag.textContent = date.toLocaleString(undefined, { +Array.from(document.getElementsByTagName('time')).forEach(timeTag => { + const datetime = timeTag.getAttribute('datetime'); + const currentText = timeTag.textContent.trim(); + // Only format if current text contains precise time. + if (currentText.match(/\d{2}:\d{2}/)) { + const date = new Date(datetime); + timeTag.textContent = date.toLocaleString( + undefined, + { year: 'numeric', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit', hour12: false - }); - } - }); + }, + ); + } }); diff --git a/web/template/profile.tmpl b/web/template/profile.tmpl index 0456644c9..7518129cb 100644 --- a/web/template/profile.tmpl +++ b/web/template/profile.tmpl @@ -180,7 +180,7 @@ {{- end }} {{- end }} - +
diff --git a/web/template/status_attributes.tmpl b/web/template/status_attributes.tmpl index b356a76e9..a99775d59 100644 --- a/web/template/status_attributes.tmpl +++ b/web/template/status_attributes.tmpl @@ -18,7 +18,7 @@ */ -}} {{- define "ariaLabel" -}} -@{{ .Account.Acct -}}, {{ timestamp .CreatedAt -}} +@{{ .Account.Acct -}}, {{ .CreatedAt | timestampPrecise -}} (server time) {{- if .LanguageTag -}} , language {{ .LanguageTag.DisplayStr -}} {{- end -}} @@ -52,5 +52,4 @@ id="{{- .ID -}}{{- if .Pinned -}}-pinned{{- end -}}" role="region" aria-label="{{- template "ariaLabel" . -}}" -class="status expanded h-entry" {{- end }} \ No newline at end of file diff --git a/web/template/status_info.tmpl b/web/template/status_info.tmpl index 2f81591a6..194a799f5 100644 --- a/web/template/status_info.tmpl +++ b/web/template/status_info.tmpl @@ -23,14 +23,14 @@
Published
- +
{{- if .EditedAt -}}
Edited
- (edited ) + (edited )
{{ end }} diff --git a/web/template/status_poll.tmpl b/web/template/status_poll.tmpl index 8b3f0c60a..9c2d29166 100644 --- a/web/template/status_poll.tmpl +++ b/web/template/status_poll.tmpl @@ -40,9 +40,9 @@ Poll  {{- end -}} {{- if .Poll.Expired -}} - closed + closed {{- else if .Poll.ExpiresAt -}} - open until + open until {{- else -}} open forever {{- end -}}