diff --git a/.gitignore b/.gitignore index 78d9478..1a13e8e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ # Ignore the executable amsterdam +__debug_bin* + diff --git a/config/config.go b/config/config.go index cf546a3..e6d0c2e 100644 --- a/config/config.go +++ b/config/config.go @@ -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. diff --git a/config/default.yaml b/config/default.yaml index 8f38d70..16c1d39 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -37,3 +37,5 @@ email: rendering: templatedir: custom_templates cookiekey: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz + countryList: + prioritize: US diff --git a/ui/templates.go b/ui/templates.go index 0fd7828..5275508 100644 --- a/ui/templates.go +++ b/ui/templates.go @@ -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 }