allow country list to "prioritize" a country (configurable)
This commit is contained in:
@@ -1,2 +1,4 @@
|
||||
# Ignore the executable
|
||||
amsterdam
|
||||
__debug_bin*
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -37,3 +37,5 @@ email:
|
||||
rendering:
|
||||
templatedir: custom_templates
|
||||
cookiekey: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
|
||||
countryList:
|
||||
prioritize: US
|
||||
|
||||
+14
-3
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user