diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-08-05 14:10:58 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-09-06 18:32:17 +0300 |
commit | 90de511017f9dcc65cccd7d161c70f326df3ab5b (patch) | |
tree | 072938c9f0c982b6464a96954468fbbfd6afd63d /commands | |
parent | 36f2a1f676c6e8821d2d1600c696dcb2658d1cc9 (diff) |
Make taxonomies configurable per language
See #2312
Diffstat (limited to 'commands')
-rw-r--r-- | commands/hugo.go | 4 | ||||
-rw-r--r-- | commands/multilingual.go | 75 |
2 files changed, 2 insertions, 77 deletions
diff --git a/commands/hugo.go b/commands/hugo.go index 9ad46b3bf..3c5236268 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -493,12 +493,12 @@ func InitializeConfig(subCmdVs ...*cobra.Command) error { helpers.HugoReleaseVersion(), minVersion) } - h, err := readMultilingualConfiguration() + h, err := hugolib.NewHugoSitesFromConfiguration() if err != nil { return err } - //TODO(bep) refactor ... + //TODO(bep) ml refactor ... Hugo = h return nil diff --git a/commands/multilingual.go b/commands/multilingual.go deleted file mode 100644 index 16f392acc..000000000 --- a/commands/multilingual.go +++ /dev/null @@ -1,75 +0,0 @@ -package commands - -import ( - "fmt" - "sort" - - "strings" - - "github.com/spf13/cast" - "github.com/spf13/hugo/hugolib" - "github.com/spf13/viper" -) - -func readMultilingualConfiguration() (*hugolib.HugoSites, error) { - sites := make([]*hugolib.Site, 0) - multilingual := viper.GetStringMap("Languages") - if len(multilingual) == 0 { - // TODO(bep) multilingo langConfigsList = append(langConfigsList, hugolib.NewLanguage("en")) - sites = append(sites, hugolib.NewSite(hugolib.NewLanguage("en"))) - } - - if len(multilingual) > 0 { - var err error - - languages, err := toSortedLanguages(multilingual) - - if err != nil { - return nil, fmt.Errorf("Failed to parse multilingual config: %s", err) - } - - for _, lang := range languages { - sites = append(sites, hugolib.NewSite(lang)) - } - - } - - return hugolib.NewHugoSites(sites...) - -} - -func toSortedLanguages(l map[string]interface{}) (hugolib.Languages, error) { - langs := make(hugolib.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 := hugolib.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 -} |