From bc99dc990ac4e473c32a18a5f824e7d69d863e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferdinand=20M=C3=BCtsch?= Date: Fri, 7 Oct 2022 08:58:51 +0200 Subject: [PATCH] fix: case sensitivity with leaderboard languages (resolve #418) --- models/leaderboard.go | 7 ++++--- models/view/leaderboard.go | 1 - routes/leaderboard.go | 3 ++- views/leaderboard.tpl.html | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/models/leaderboard.go b/models/leaderboard.go index 6b7bc38..17f1771 100644 --- a/models/leaderboard.go +++ b/models/leaderboard.go @@ -45,10 +45,11 @@ func (l Leaderboard) TopKeys(by uint8) []string { if item.Key == nil || item.By == nil || *item.By != by { continue } - if _, ok := totalsMapped[*item.Key]; !ok { - totalsMapped[*item.Key] = &keyTotal{Key: *item.Key, Total: 0} + key := strings.ToLower(*item.Key) + if _, ok := totalsMapped[key]; !ok { + totalsMapped[key] = &keyTotal{Key: *item.Key, Total: 0} } - totalsMapped[*item.Key].Total += item.Total + totalsMapped[key].Total += item.Total } totals := slice.Map[*keyTotal, keyTotal](maputil.Values[string, *keyTotal](totalsMapped), func(i int, item *keyTotal) keyTotal { diff --git a/models/view/leaderboard.go b/models/view/leaderboard.go index 6cb5c53..b564cc0 100644 --- a/models/view/leaderboard.go +++ b/models/view/leaderboard.go @@ -47,7 +47,6 @@ func (s *LeaderboardViewModel) ColorModifier(item *models.LeaderboardItem, princ func (s *LeaderboardViewModel) LangIcon(lang string) string { // https://icon-sets.iconify.design/mdi/ langs := map[string]string{ - "c": "c", "c++": "cpp", "cpp": "cpp", "go": "go", diff --git a/routes/leaderboard.go b/routes/leaderboard.go index ffb6d3d..7e4c625 100644 --- a/routes/leaderboard.go +++ b/routes/leaderboard.go @@ -87,8 +87,9 @@ func (h *LeaderboardHandler) buildViewModel(r *http.Request) *view.LeaderboardVi topKeys = leaderboard.TopKeys(by) if len(topKeys) > 0 { if keyParam == "" { - keyParam = strings.ToLower(topKeys[0]) + keyParam = topKeys[0] } + keyParam = strings.ToLower(keyParam) leaderboard = leaderboard.TopByKey(by, keyParam) } } else { diff --git a/views/leaderboard.tpl.html b/views/leaderboard.tpl.html index 4841f24..124763b 100644 --- a/views/leaderboard.tpl.html +++ b/views/leaderboard.tpl.html @@ -23,7 +23,7 @@

Leaderboard

- Wakapi's leaderboard shows a ranking of the most active users on this servers, given they opted in to get listed on the public leaderboard. Statistics are updated at least every 12 hours and are based on the users' total coding time in the past seven days. + Wakapi's leaderboard shows a ranking of the most active users on this server, given they opted in to get listed on the public leaderboard. Statistics are updated at least every 12 hours and are based on the users' total coding time in the past seven days. To participate, log in, go to Settings 🠒 Permissions and enable leaderboards.

@@ -40,7 +40,7 @@
{{ range $i, $key := (strslice .TopKeys 0 10) }}