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.
This commit is contained in:
jordi fita mas 2023-08-07 11:00:14 +02:00
parent e59e6a2a42
commit 477865477b
1 changed files with 4 additions and 4 deletions

View File

@ -6,13 +6,13 @@
package app package app
import ( import (
"fmt"
"net/http"
"dev.tandem.ws/tandem/camper/pkg/auth" "dev.tandem.ws/tandem/camper/pkg/auth"
"dev.tandem.ws/tandem/camper/pkg/database" "dev.tandem.ws/tandem/camper/pkg/database"
httplib "dev.tandem.ws/tandem/camper/pkg/http" httplib "dev.tandem.ws/tandem/camper/pkg/http"
"dev.tandem.ws/tandem/camper/pkg/template" "dev.tandem.ws/tandem/camper/pkg/template"
"fmt"
"net/http"
"sort"
) )
type publicHandler struct{} 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), 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) template.MustRenderPublic(w, r, user, company, p.template, p)
} }