github.com/anakojm/hugo-katex@v0.0.0-20231023141351-42d6f5de9c0b/langs/config.go (about) 1 // Copyright 2018 The Hugo Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package langs 15 16 import ( 17 "errors" 18 19 "github.com/gohugoio/hugo/common/maps" 20 "github.com/mitchellh/mapstructure" 21 ) 22 23 // LanguageConfig holds the configuration for a single language. 24 // This is what is read from the config file. 25 type LanguageConfig struct { 26 // The language name, e.g. "English". 27 LanguageName string 28 29 // The language code, e.g. "en-US". 30 LanguageCode string 31 32 // The language title. When set, this will 33 // override site.Title for this language. 34 Title string 35 36 // The language direction, e.g. "ltr" or "rtl". 37 LanguageDirection string 38 39 // The language weight. When set to a non-zero value, this will 40 // be the main sort criteria for the language. 41 Weight int 42 43 // Set to true to disable this language. 44 Disabled bool 45 } 46 47 func DecodeConfig(m map[string]any) (map[string]LanguageConfig, error) { 48 m = maps.CleanConfigStringMap(m) 49 var langs map[string]LanguageConfig 50 51 if err := mapstructure.WeakDecode(m, &langs); err != nil { 52 return nil, err 53 } 54 if len(langs) == 0 { 55 return nil, errors.New("no languages configured") 56 } 57 return langs, nil 58 }