| 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/hmaps" |
| 20 |
"github.com/gohugoio/hugo/common/paths" |
| 21 |
"github.com/gohugoio/hugo/common/types" |
| 22 |
"github.com/gohugoio/hugo/common/urls" |
| 23 |
"github.com/gohugoio/hugo/hugolib/sitesmatrix" |
| 24 |
"github.com/gohugoio/hugo/identity" |
| 25 |
) |
| 26 |
|
| 27 |
// AllProvider is a sub set of all config settings. |
| 28 |
type AllProvider interface { |
| 29 |
Language() any |
| 30 |
LanguageIndex() int |
| 31 |
Languages() any |
| 32 |
LanguagePrefix() string |
| 33 |
BaseURL() urls.BaseURL |
| 34 |
BaseURLLiveReload() urls.BaseURL |
| 35 |
PathParser() *paths.PathParser |
| 36 |
Environment() string |
| 37 |
IsMultihost() bool |
| 38 |
IsMultilingual() bool |
| 39 |
NoBuildLock() bool |
| 40 |
BaseConfig() BaseConfig |
| 41 |
Dirs() CommonDirs |
| 42 |
Quiet() bool |
| 43 |
DirsBase() CommonDirs |
| 44 |
FileCaches() any |
| 45 |
ContentTypes() ContentTypesProvider |
| 46 |
GetConfigSection(string) any |
| 47 |
GetConfig() any |
| 48 |
CanonifyURLs() bool |
| 49 |
DisablePathToLower() bool |
| 50 |
RemovePathAccents() bool |
| 51 |
IsUglyURLs(section string) bool |
| 52 |
DefaultContentLanguage() string |
| 53 |
DefaultContentLanguageInSubdir() bool |
| 54 |
DefaultContentRoleInSubdir() bool |
| 55 |
DefaultContentVersionInSubdir() bool |
| 56 |
DefaultContentsitesMatrix() *sitesmatrix.IntSets |
| 57 |
AllSitesMatrix() *sitesmatrix.IntSets |
| 58 |
IsKindEnabled(string) bool |
| 59 |
IsLangDisabled(string) bool |
| 60 |
SummaryLength() int |
| 61 |
Pagination() Pagination |
| 62 |
BuildExpired() bool |
| 63 |
BuildFuture() bool |
| 64 |
BuildDrafts() bool |
| 65 |
Running() bool |
| 66 |
Watching() bool |
| 67 |
NewIdentityManager(opts ...identity.ManagerOption) identity.Manager |
| 68 |
FastRenderMode() bool |
| 69 |
PrintUnusedTemplates() bool |
| 70 |
EnableMissingTranslationPlaceholders() bool |
| 71 |
IgnoreTailwindCSSSecurityError() bool |
| 72 |
TemplateMetrics() bool |
| 73 |
TemplateMetricsHints() bool |
| 74 |
PrintI18nWarnings() bool |
| 75 |
CreateTitle(s string) string |
| 76 |
IgnoreFile(s string) bool |
| 77 |
NewContentEditor() string |
| 78 |
Timeout() time.Duration |
| 79 |
StaticDirs() []string |
| 80 |
IgnoredLogs() map[string]bool |
| 81 |
WorkingDir() string |
| 82 |
EnableEmoji() bool |
| 83 |
ConfiguredDimensions() *sitesmatrix.ConfiguredDimensions |
| 84 |
CacheDirMisc() string |
| 85 |
} |
| 86 |
|
| 87 |
// We cannot import the media package as that would create a circular dependency. |
| 88 |
// This interface defines a subset of what media.ContentTypes provides. |
| 89 |
type ContentTypesProvider interface { |
| 90 |
IsContentSuffix(suffix string) bool |
| 91 |
IsContentFile(filename string) bool |
| 92 |
IsIndexContentFile(filename string) bool |
| 93 |
IsHTMLSuffix(suffix string) bool |
| 94 |
} |
| 95 |
|
| 96 |
// Provider provides the configuration settings for Hugo. |
| 97 |
type Provider interface { |
| 98 |
GetString(key string) string |
| 99 |
GetInt(key string) int |
| 100 |
GetBool(key string) bool |
| 101 |
GetParams(key string) hmaps.Params |
| 102 |
GetStringMap(key string) map[string]any |
| 103 |
GetStringMapString(key string) map[string]string |
| 104 |
GetStringSlice(key string) []string |
| 105 |
Get(key string) any |
| 106 |
Set(key string, value any) |
| 107 |
Keys() []string |
| 108 |
Merge(key string, value any) |
| 109 |
SetDefaults(params hmaps.Params) |
| 110 |
SetDefaultMergeStrategy() |
| 111 |
WalkParams(walkFn func(params ...hmaps.KeyParams) bool) |
| 112 |
IsSet(key string) bool |
| 113 |
} |
| 114 |
|
| 115 |
// GetStringSlicePreserveString returns a string slice from the given config and key. |
| 116 |
// It differs from the GetStringSlice method in that if the config value is a string, |
| 117 |
// we do not attempt to split it into fields. |
| 118 |
func GetStringSlicePreserveString(cfg Provider, key string) []string { |
| 119 |
sd := cfg.Get(key) |
| 120 |
return types.ToStringSlicePreserveString(sd) |
| 121 |
} |
| 122 |
|
| 123 |
/*func (cd ConfiguredDimensions) Language(v sitesmatrix.Vector) ConfiguredDimension { |
| 124 |
}*/ |