diff --git a/appview/pages/funcmap.go b/appview/pages/funcmap.go index 6a8b9780..2944d510 100644 --- a/appview/pages/funcmap.go +++ b/appview/pages/funcmap.go @@ -178,6 +178,30 @@ func (p *Pages) funcMap() template.FuncMap { 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 index c9327969..e01833c8 100644 --- 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 index 57ca1086..fbe814dd 100644 --- 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 index 34aa76ad..b6438d10 100644 --- 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 index bc63e81d..c8adf05e 100644 --- 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 }}