Make taxonomies configurable per language

See #2312
This commit is contained in:
Bjørn Erik Pedersen
2016-08-05 13:10:58 +02:00
parent 36f2a1f676
commit 90de511017
9 changed files with 150 additions and 113 deletions

View File

@@ -6,6 +6,8 @@ import (
"sort"
"strings"
"fmt"
"github.com/spf13/cast"
"github.com/spf13/viper"
)
@@ -112,3 +114,39 @@ func (s *Site) currentLanguageString() string {
func (s *Site) currentLanguage() *Language {
return s.Language
}
func toSortedLanguages(l map[string]interface{}) (Languages, error) {
langs := make(Languages, len(l))
i := 0
for lang, langConf := range l {
langsMap, ok := langConf.(map[string]interface{})
if !ok {
return nil, fmt.Errorf("Language config is not a map: %v", langsMap)
}
language := NewLanguage(lang)
for k, v := range langsMap {
loki := strings.ToLower(k)
switch loki {
case "title":
language.Title = cast.ToString(v)
case "weight":
language.Weight = cast.ToInt(v)
}
// Put all into the Params map
// TODO(bep) reconsile with the type handling etc. from other params handlers.
language.SetParam(loki, v)
}
langs[i] = language
i++
}
sort.Sort(langs)
return langs, nil
}