From 477865477bab21aebe45f3abd0bdaf73a192c804 Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Mon, 7 Aug 2023 11:00:14 +0200 Subject: [PATCH] Sort the list of localized alternate links Since the locales is a map, and maps in Go do not have order, sometime the language switcher was shown in a different order. I sort by language code, which is as arbitrary as sorting by name, but makes sense to me. --- pkg/app/public.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/app/public.go b/pkg/app/public.go index c58dbd9..2d672b8 100644 --- a/pkg/app/public.go +++ b/pkg/app/public.go @@ -6,13 +6,13 @@ package app import ( - "fmt" - "net/http" - "dev.tandem.ws/tandem/camper/pkg/auth" "dev.tandem.ws/tandem/camper/pkg/database" httplib "dev.tandem.ws/tandem/camper/pkg/http" "dev.tandem.ws/tandem/camper/pkg/template" + "fmt" + "net/http" + "sort" ) type publicHandler struct{} @@ -65,7 +65,7 @@ func (p *PublicPage) MustRender(w http.ResponseWriter, r *http.Request, user *au HRef: fmt.Sprintf("%s://%s/%s%s", schema, authority, l.Language, path), }) } - + sort.Slice(p.LocalizedAlternates, func(i, j int) bool { return p.LocalizedAlternates[i].Lang < p.LocalizedAlternates[j].Lang }) template.MustRenderPublic(w, r, user, company, p.template, p) }