summaryrefslogtreecommitdiffhomepage
path: root/templates
diff options
context:
space:
mode:
Diffstat (limited to 'templates')
-rw-r--r--templates/base.go35
-rw-r--r--templates/coins_designs.templ2
2 files changed, 32 insertions, 5 deletions
diff --git a/templates/base.go b/templates/base.go
index ba31baf..76a4da6 100644
--- a/templates/base.go
+++ b/templates/base.go
@@ -2,12 +2,28 @@
package templates
-import "git.thomasvoss.com/euro-cash.eu/i18n"
+import (
+ "fmt"
+ "slices"
-type country struct{ code, name string }
+ "git.thomasvoss.com/euro-cash.eu/i18n"
+ "golang.org/x/text/collate"
+ "golang.org/x/text/language"
+)
-func countries(p i18n.Printer) []country {
- return []country{
+type country struct {
+ code, name string
+}
+
+type sortType int
+
+const (
+ sortByCode sortType = iota
+ sortByName
+)
+
+func countries(p i18n.Printer, sort sortType) []country {
+ xs := []country{
{code: "AD", name: p.T("Andorra")},
{code: "AT", name: p.T("Austria")},
{code: "BE", name: p.T("Belgium")},
@@ -33,4 +49,15 @@ func countries(p i18n.Printer) []country {
{code: "SM", name: p.T("San Marino")},
{code: "VA", name: p.T("Vatican City")},
}
+ switch sort {
+ case sortByCode:
+ case sortByName:
+ c := collate.New(language.MustParse(p.Locale.Bcp))
+ slices.SortFunc(xs, func(x, y country) int {
+ return c.CompareString(x.name, y.name)
+ })
+ default:
+ panic(fmt.Sprintf("Attempted to sort by invalid sortType=%d", sort))
+ }
+ return xs
}
diff --git a/templates/coins_designs.templ b/templates/coins_designs.templ
index 1b1ba6d..6d186e1 100644
--- a/templates/coins_designs.templ
+++ b/templates/coins_designs.templ
@@ -26,7 +26,7 @@ templ CoinsDesigns() {
</p>
<hr/>
<div class="country-grid">
- for _, c := range countries(p) {
+ for _, c := range countries(p, sortByCode) {
<a
role="button"
class="outline"