allow country list to "prioritize" a country (configurable)

This commit is contained in:
2025-10-09 14:56:37 -06:00
parent 7cd5071927
commit 782fba2c32
4 changed files with 22 additions and 3 deletions
+2
View File
@@ -1,2 +1,4 @@
# Ignore the executable
amsterdam
__debug_bin*
+4
View File
@@ -76,6 +76,9 @@ type AmConfig struct {
Rendering struct {
TemplateDir string `yaml:"templatedir"`
CookieKey string `yaml:"cookiekey"`
CountryList struct {
Prioritize string `yaml:"prioritize"`
} `yaml:"countryList"`
} `yaml:"rendering"`
}
@@ -151,6 +154,7 @@ func overlayConfig(dest *AmConfig, loaded *AmConfig, defaults *AmConfig) {
dest.Email.Disclaimer = overlayString(loaded.Email.Disclaimer, defaults.Email.Disclaimer)
dest.Rendering.TemplateDir = overlayString(loaded.Rendering.TemplateDir, defaults.Rendering.TemplateDir)
dest.Rendering.CookieKey = overlayString(loaded.Rendering.CookieKey, defaults.Rendering.CookieKey)
dest.Rendering.CountryList.Prioritize = overlayString(loaded.Rendering.CountryList.Prioritize, defaults.Rendering.CountryList.Prioritize)
}
// SetupConfig loads the command line arguments, loads the config file, and prepares GlobalConfig.
+2
View File
@@ -37,3 +37,5 @@ email:
rendering:
templatedir: custom_templates
cookiekey: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
countryList:
prioritize: US
+14 -3
View File
@@ -49,11 +49,22 @@ func internalGetCountryList() []countries.CountryCode {
countryListMutex.Lock()
defer countryListMutex.Unlock()
if cachedCountryList == nil {
c := countries.All()
slices.SortFunc(c, func(a countries.CountryCode, b countries.CountryCode) int {
countryList := countries.All()
slices.SortFunc(countryList, func(a countries.CountryCode, b countries.CountryCode) int {
return strings.Compare(a.Info().Name, b.Info().Name)
})
cachedCountryList = c
if config.GlobalConfig.Rendering.CountryList.Prioritize != "" {
for i, c := range countryList {
if c.Info().Alpha2 == config.GlobalConfig.Rendering.CountryList.Prioritize {
newList := make([]countries.CountryCode, len(countryList))
newList[0] = c
copy(newList[1:], countryList[:i])
copy(newList[i+1:], countryList[i+1:])
countryList = newList
}
}
}
cachedCountryList = countryList
}
return cachedCountryList
}