From 06da90da07b626a5c0a75768bd08c1c4d6c17108 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Wed, 20 May 2026 08:59:21 +0000 Subject: [PATCH] appview/pages: add scaleFmt to print counts >1k better Signed-off-by: oppiliappan --- appview/pages/funcmap.go | 24 ++++++++++++++++++++++++ appview/pages/templates/fragments/starBtn.html | 4 ++-- appview/pages/templates/layouts/profilebase.html | 2 +- appview/pages/templates/layouts/repobase.html | 4 ++-- appview/pages/templates/repo/issues/issues.html | 4 ++-- appview/pages/templates/repo/pulls/pulls.html | 6 +++--- appview/pages/templates/user/fragments/repoCard.html | 8 ++++---- 7 file(s) changed, 38 insertion(s)(+), 14 deletion(s)(-) diff --git a/appview/pages/funcmap.go b/appview/pages/funcmap.go --- a/appview/pages/funcmap.go +++ b/appview/pages/funcmap.go @@ -178,6 +178,30 @@ s = append(s, values...) return s }, + // scale numerics over 1000 to 1k + "scaleFmt": func(n any) string { + var v float64 + switch x := n.(type) { + case int: + v = float64(x) + case int32: + v = float64(x) + case int64: + v = float64(x) + case float64: + v = x + default: + return fmt.Sprintf("%v", n) + } + if v < 1000 { + return fmt.Sprintf("%d", int(v)) + } + k := v / 1000 + if k < 10 { + return fmt.Sprintf("%.1fk", k) + } + return fmt.Sprintf("%dk", int(k)) + }, "commaFmt": humanize.Comma, "plural": english.Plural, "relTimeFmt": humanize.Time, diff --git a/appview/pages/templates/fragments/starBtn.html b/appview/pages/templates/fragments/starBtn.html --- a/appview/pages/templates/fragments/starBtn.html +++ b/appview/pages/templates/fragments/starBtn.html @@ -31,11 +31,11 @@ class="btn-group-item" title="Starred by" > - {{ .StarCount }} + {{ scaleFmt .StarCount }} {{ else }} - {{ .StarCount }} + {{ scaleFmt .StarCount }} {{ end }} diff --git a/appview/pages/templates/layouts/profilebase.html b/appview/pages/templates/layouts/profilebase.html --- a/appview/pages/templates/layouts/profilebase.html +++ b/appview/pages/templates/layouts/profilebase.html @@ -91,7 +91,7 @@ {{ i $icon "w-4 h-4 mr-2" }} {{ $key }} {{ if $meta }} - {{ $meta }} + {{ scaleFmt $meta }} {{ end }} diff --git a/appview/pages/templates/layouts/repobase.html b/appview/pages/templates/layouts/repobase.html --- a/appview/pages/templates/layouts/repobase.html +++ b/appview/pages/templates/layouts/repobase.html @@ -47,7 +47,7 @@ {{ i $icon "w-4 h-4 mr-2" }} {{ $key }} {{ if $meta }} - {{ $meta }} + {{ scaleFmt $meta }} {{ end }} @@ -132,7 +132,7 @@ class="btn-group-item" title="Forked by" > - {{ .RepoInfo.Stats.ForkCount }} + {{ scaleFmt .RepoInfo.Stats.ForkCount }} {{ template "repo/fragments/feedDropdown" . }} diff --git a/appview/pages/templates/repo/issues/issues.html b/appview/pages/templates/repo/issues/issues.html --- a/appview/pages/templates/repo/issues/issues.html +++ b/appview/pages/templates/repo/issues/issues.html @@ -15,13 +15,13 @@ "Key" "open" "Value" "open" "Icon" "circle-dot" - "Meta" (string .RepoInfo.Stats.IssueCount.Open)) }} + "Meta" (scaleFmt .RepoInfo.Stats.IssueCount.Open)) }} {{ $closed := (dict "Key" "closed" "Value" "closed" "Icon" "ban" - "Meta" (string .RepoInfo.Stats.IssueCount.Closed)) }} + "Meta" (scaleFmt .RepoInfo.Stats.IssueCount.Closed)) }} {{ $values := list $open $closed }}
diff --git a/appview/pages/templates/repo/pulls/pulls.html b/appview/pages/templates/repo/pulls/pulls.html --- a/appview/pages/templates/repo/pulls/pulls.html +++ b/appview/pages/templates/repo/pulls/pulls.html @@ -14,19 +14,19 @@ "Key" "open" "Value" "open" "Icon" "git-pull-request" - "Meta" (string .RepoInfo.Stats.PullCount.Open)) }} + "Meta" (scaleFmt .RepoInfo.Stats.PullCount.Open)) }} {{ $merged := (dict "Key" "merged" "Value" "merged" "Icon" "git-merge" - "Meta" (string .RepoInfo.Stats.PullCount.Merged)) }} + "Meta" (scaleFmt .RepoInfo.Stats.PullCount.Merged)) }} {{ $closed := (dict "Key" "closed" "Value" "closed" "Icon" "ban" - "Meta" (string .RepoInfo.Stats.PullCount.Closed)) }} + "Meta" (scaleFmt .RepoInfo.Stats.PullCount.Closed)) }} {{ $values := list $open $merged $closed }}
diff --git a/appview/pages/templates/user/fragments/repoCard.html b/appview/pages/templates/user/fragments/repoCard.html --- a/appview/pages/templates/user/fragments/repoCard.html +++ b/appview/pages/templates/user/fragments/repoCard.html @@ -62,25 +62,25 @@ {{ with .StarCount }}
{{ i "star" "w-3 h-3 fill-current" }} - {{ . }} + {{ scaleFmt . }}
{{ end }} {{ with .ForkCount }}
{{ i "git-fork" "w-3 h-3" }} - {{ . }} + {{ scaleFmt . }}
{{ end }} {{ with .IssueCount.Open }}
{{ i "circle-dot" "w-3 h-3" }} - {{ . }} + {{ scaleFmt . }}
{{ end }} {{ with .PullCount.Open }}
{{ i "git-pull-request" "w-3 h-3" }} - {{ . }} + {{ scaleFmt . }}
{{ end }}
-- tangled.sh