github.com/anakojm/hugo-katex@v0.0.0-20231023141351-42d6f5de9c0b/config/configProvider.go (about) 1 // Copyright 2019 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 config 15 16 import ( 17 "time" 18 19 "github.com/gohugoio/hugo/common/maps" 20 "github.com/gohugoio/hugo/common/types" 21 "github.com/gohugoio/hugo/common/urls" 22 "github.com/gohugoio/hugo/langs" 23 ) 24 25 // AllProvider is a sub set of all config settings. 26 type AllProvider interface { 27 Language() *langs.Language 28 Languages() langs.Languages 29 LanguagesDefaultFirst() langs.Languages 30 LanguagePrefix() string 31 BaseURL() urls.BaseURL 32 BaseURLLiveReload() urls.BaseURL 33 Environment() string 34 IsMultihost() bool 35 IsMultiLingual() bool 36 NoBuildLock() bool 37 BaseConfig() BaseConfig 38 Dirs() CommonDirs 39 Quiet() bool 40 DirsBase() CommonDirs 41 GetConfigSection(string) any 42 GetConfig() any 43 CanonifyURLs() bool 44 DisablePathToLower() bool 45 RemovePathAccents() bool 46 IsUglyURLs(section string) bool 47 DefaultContentLanguage() string 48 DefaultContentLanguageInSubdir() bool 49 IsLangDisabled(string) bool 50 SummaryLength() int 51 Paginate() int 52 PaginatePath() string 53 BuildExpired() bool 54 BuildFuture() bool 55 BuildDrafts() bool 56 Running() bool 57 PrintUnusedTemplates() bool 58 EnableMissingTranslationPlaceholders() bool 59 TemplateMetrics() bool 60 TemplateMetricsHints() bool 61 PrintI18nWarnings() bool 62 CreateTitle(s string) string 63 IgnoreFile(s string) bool 64 NewContentEditor() string 65 Timeout() time.Duration 66 StaticDirs() []string 67 IgnoredErrors() map[string]bool 68 WorkingDir() string 69 } 70 71 // Provider provides the configuration settings for Hugo. 72 type Provider interface { 73 GetString(key string) string 74 GetInt(key string) int 75 GetBool(key string) bool 76 GetParams(key string) maps.Params 77 GetStringMap(key string) map[string]any 78 GetStringMapString(key string) map[string]string 79 GetStringSlice(key string) []string 80 Get(key string) any 81 Set(key string, value any) 82 Keys() []string 83 Merge(key string, value any) 84 SetDefaults(params maps.Params) 85 SetDefaultMergeStrategy() 86 WalkParams(walkFn func(params ...maps.KeyParams) bool) 87 IsSet(key string) bool 88 } 89 90 // GetStringSlicePreserveString returns a string slice from the given config and key. 91 // It differs from the GetStringSlice method in that if the config value is a string, 92 // we do not attempt to split it into fields. 93 func GetStringSlicePreserveString(cfg Provider, key string) []string { 94 sd := cfg.Get(key) 95 return types.ToStringSlicePreserveString(sd) 96 } 97 98 func setIfNotSet(cfg Provider, key string, value any) { 99 if !cfg.IsSet(key) { 100 cfg.Set(key, value) 101 } 102 }