From 1c03f0a07ab05faa53429996a061b6ca908d9654 Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Tue, 14 Jan 2025 10:41:46 +0000 Subject: [PATCH] Update forum post templates * Use approx number for points & comments * Hide comments when limited on horizontal space * Abbreviate "points" to "pts" when limited on horizontal space * Don't let domain wrap --- internal/glance/static/main.css | 22 ++++++++++++++----- internal/glance/templates.go | 13 +++++------ internal/glance/templates/dns-stats.html | 2 +- internal/glance/templates/forum-posts.html | 6 ++--- .../templates/reddit-horizontal-cards.html | 2 +- .../templates/reddit-vertical-cards.html | 2 +- .../glance/templates/twitch-channels.html | 2 +- .../glance/templates/twitch-games-list.html | 2 +- 8 files changed, 30 insertions(+), 21 deletions(-) diff --git a/internal/glance/static/main.css b/internal/glance/static/main.css index 5312e64..2a5db10 100644 --- a/internal/glance/static/main.css +++ b/internal/glance/static/main.css @@ -804,7 +804,7 @@ details[open] .summary::after { .list-horizontal-text > *:not(:last-child)::after { content: '•'; color: var(--color-text-subdue); - margin: 0 0.5rem; + margin: 0 0.4rem; position: relative; top: 0.1rem; } @@ -1023,11 +1023,6 @@ details[open] .summary::after { display: none; } -.forum-post-list-item { - display: flex; - gap: 1.2rem; -} - .forum-post-list-thumbnail { flex-shrink: 0; width: 6rem; @@ -1042,6 +1037,21 @@ details[open] .summary::after { transform: translateY(-0.15rem); } +@container widget (max-width: 550px) { + .forum-post-comment-count { + display: none; + } + + .forum-post-points-word { + font-size: 0; + } + + .forum-post-points-word::after { + content: "pts"; + font-size: var(--font-size-base); + } +} + .bookmarks-group { --bookmarks-group-color: var(--color-primary); } diff --git a/internal/glance/templates.go b/internal/glance/templates.go index d9b1a6c..fb2cb13 100644 --- a/internal/glance/templates.go +++ b/internal/glance/templates.go @@ -1,7 +1,6 @@ package glance import ( - "fmt" "html/template" "math" "strconv" @@ -14,8 +13,8 @@ import ( var intl = message.NewPrinter(language.English) var globalTemplateFunctions = template.FuncMap{ - "formatViewerCount": formatViewerCount, - "formatNumber": intl.Sprint, + "formatApproxNumber": formatApproxNumber, + "formatNumber": intl.Sprint, "safeCSS": func(str string) template.CSS { return template.CSS(str) }, @@ -45,18 +44,18 @@ func mustParseTemplate(primary string, dependencies ...string) *template.Templat return t } -func formatViewerCount(count int) string { +func formatApproxNumber(count int) string { if count < 1_000 { return strconv.Itoa(count) } if count < 10_000 { - return fmt.Sprintf("%.1fk", float64(count)/1_000) + return strconv.FormatFloat(float64(count)/1_000, 'f', 1, 64) + "k" } if count < 1_000_000 { - return fmt.Sprintf("%dk", count/1_000) + return strconv.Itoa(count/1_000) + "k" } - return fmt.Sprintf("%.1fm", float64(count)/1_000_000) + return strconv.FormatFloat(float64(count)/1_000_000, 'f', 1, 64) + "m" } diff --git a/internal/glance/templates/dns-stats.html b/internal/glance/templates/dns-stats.html index 7938038..8128edf 100644 --- a/internal/glance/templates/dns-stats.html +++ b/internal/glance/templates/dns-stats.html @@ -18,7 +18,7 @@ {{ else }}