Debian Codegraph @

config/allconfig/configlanguage.go

raw
1 // Copyright 2024 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 allconfig
15
16 import (
17 "time"
18
19 "github.com/gohugoio/hugo/common/paths"
20 "github.com/gohugoio/hugo/common/urls"
21 "github.com/gohugoio/hugo/config"
22 "github.com/gohugoio/hugo/hugolib/sitesmatrix"
23 "github.com/gohugoio/hugo/identity"
24 "github.com/gohugoio/hugo/langs"
25 )
26
27 type ConfigLanguage struct {
28 config *Config
29 baseConfig config.BaseConfig
30 m *Configs
31 language *langs.Language
32 languageIndex int
33 }
34
35 func (c ConfigLanguage) Language() any {
36 return c.language
37 }
38
39 func (c ConfigLanguage) LanguageIndex() int {
40 return c.languageIndex
41 }
42
43 func (c ConfigLanguage) Languages() any {
44 return c.m.Languages
45 }
46
47 func (c ConfigLanguage) PathParser() *paths.PathParser {
48 return c.m.ContentPathParser
49 }
50
51 func (c ConfigLanguage) LanguagePrefix() string {
52 if c.DefaultContentLanguageInSubdir() && c.DefaultContentLanguage() == c.language.Lang {
53 return c.language.Lang
54 }
55
56 if !c.IsMultilingual() || c.DefaultContentLanguage() == c.language.Lang {
57 return ""
58 }
59 return c.language.Lang
60 }
61
62 func (c ConfigLanguage) BaseURL() urls.BaseURL {
63 return c.config.C.BaseURL
64 }
65
66 func (c ConfigLanguage) BaseURLLiveReload() urls.BaseURL {
67 return c.config.C.BaseURLLiveReload
68 }
69
70 // AllBaseURLs returns the BaseURL for each enabled language, ordered as Languages().
71 func (c ConfigLanguage) AllBaseURLs() []urls.BaseURL {
72 bs := make([]urls.BaseURL, len(c.m.configLangs))
73 for i, p := range c.m.configLangs {
74 bs[i] = p.BaseURL()
75 }
76 return bs
77 }
78
79 func (c ConfigLanguage) Environment() string {
80 return c.config.Environment
81 }
82
83 func (c ConfigLanguage) IsMultihost() bool {
84 if len(c.m.Languages)-len(c.config.C.DisabledLanguages) <= 1 {
85 return false
86 }
87 return c.m.IsMultihost
88 }
89
90 func (c ConfigLanguage) FastRenderMode() bool {
91 return c.config.Internal.FastRenderMode
92 }
93
94 func (c ConfigLanguage) IsMultilingual() bool {
95 return len(c.m.Languages) > 1
96 }
97
98 func (c ConfigLanguage) TemplateMetrics() bool {
99 return c.config.TemplateMetrics
100 }
101
102 func (c ConfigLanguage) TemplateMetricsHints() bool {
103 return c.config.TemplateMetricsHints
104 }
105
106 func (c ConfigLanguage) IsLangDisabled(lang string) bool {
107 return c.config.C.DisabledLanguages[lang]
108 }
109
110 func (c ConfigLanguage) IsKindEnabled(kind string) bool {
111 return !c.config.C.DisabledKinds[kind]
112 }
113
114 func (c ConfigLanguage) IgnoredLogs() map[string]bool {
115 return c.config.C.IgnoredLogs
116 }
117
118 func (c ConfigLanguage) NoBuildLock() bool {
119 return c.config.NoBuildLock
120 }
121
122 func (c ConfigLanguage) NewContentEditor() string {
123 return c.config.NewContentEditor
124 }
125
126 func (c ConfigLanguage) Timeout() time.Duration {
127 return c.config.C.Timeout
128 }
129
130 func (c ConfigLanguage) BaseConfig() config.BaseConfig {
131 return c.baseConfig
132 }
133
134 func (c ConfigLanguage) FileCaches() any {
135 return c.m.FileCaches
136 }
137
138 func (c ConfigLanguage) Dirs() config.CommonDirs {
139 return c.config.CommonDirs
140 }
141
142 func (c ConfigLanguage) DirsBase() config.CommonDirs {
143 return c.m.Base.CommonDirs
144 }
145
146 func (c ConfigLanguage) WorkingDir() string {
147 return c.m.Base.WorkingDir
148 }
149
150 func (c ConfigLanguage) CacheDirMisc() string {
151 return c.config.Caches.CacheDirMisc()
152 }
153
154 func (c ConfigLanguage) Quiet() bool {
155 return c.m.Base.Internal.Quiet
156 }
157
158 func (c ConfigLanguage) Watching() bool {
159 return c.m.Base.Internal.Watch
160 }
161
162 func (c ConfigLanguage) NewIdentityManager(opts ...identity.ManagerOption) identity.Manager {
163 if !c.Watching() {
164 return identity.NopManager
165 }
166 return identity.NewManager(opts...)
167 }
168
169 func (c ConfigLanguage) ContentTypes() config.ContentTypesProvider {
170 return c.config.ContentTypes.Config
171 }
172
173 // GetConfigSection is mostly used in tests. The switch statement isn't complete, but what's in use.
174 func (c ConfigLanguage) GetConfigSection(s string) any {
175 switch s {
176 case "security":
177 return c.config.Security
178 case "build":
179 return c.config.Build
180 case "cascade":
181 return c.config.Cascade
182 case "frontmatter":
183 return c.config.Frontmatter
184 case "caches":
185 return c.config.Caches
186 case "markup":
187 return c.config.Markup
188 case "module":
189 return c.config.Module
190 case "mediaTypes":
191 return c.config.MediaTypes.Config
192 case "outputFormats":
193 return c.config.OutputFormats.Config
194 case "roles":
195 return c.config.Roles.Config
196 case "versions":
197 return c.config.Versions.Config
198 case "permalinks":
199 return c.config.Permalinks
200 case "minify":
201 return c.config.Minify
202 case "allModules":
203 return c.m.Modules
204 case "deployment":
205 return c.config.Deployment
206 case "httpCacheCompiled":
207 return c.config.C.HTTPCache
208 default:
209 panic("not implemented: " + s)
210 }
211 }
212
213 func (c ConfigLanguage) GetConfig() any {
214 return c.config
215 }
216
217 func (c ConfigLanguage) CanonifyURLs() bool {
218 return c.config.CanonifyURLs
219 }
220
221 func (c ConfigLanguage) IsUglyURLs(section string) bool {
222 return c.config.C.IsUglyURLSection(section)
223 }
224
225 func (c ConfigLanguage) IgnoreFile(s string) bool {
226 return c.config.C.IgnoreFile(s)
227 }
228
229 func (c ConfigLanguage) DisablePathToLower() bool {
230 return c.config.DisablePathToLower
231 }
232
233 func (c ConfigLanguage) RemovePathAccents() bool {
234 return c.config.RemovePathAccents
235 }
236
237 func (c ConfigLanguage) DefaultContentLanguage() string {
238 return c.config.DefaultContentLanguage
239 }
240
241 func (c ConfigLanguage) DefaultContentLanguageInSubdir() bool {
242 return c.config.DefaultContentLanguageInSubdir
243 }
244
245 func (c ConfigLanguage) DefaultContentRoleInSubdir() bool {
246 return c.config.DefaultContentRoleInSubdir
247 }
248
249 func (c ConfigLanguage) DefaultContentVersionInSubdir() bool {
250 return c.config.DefaultContentVersionInSubdir
251 }
252
253 func (c ConfigLanguage) SummaryLength() int {
254 return c.config.SummaryLength
255 }
256
257 func (c ConfigLanguage) BuildExpired() bool {
258 return c.config.BuildExpired
259 }
260
261 func (c ConfigLanguage) BuildFuture() bool {
262 return c.config.BuildFuture
263 }
264
265 func (c ConfigLanguage) BuildDrafts() bool {
266 return c.config.BuildDrafts
267 }
268
269 func (c ConfigLanguage) Running() bool {
270 return c.config.Internal.Running
271 }
272
273 func (c ConfigLanguage) PrintUnusedTemplates() bool {
274 return c.config.PrintUnusedTemplates
275 }
276
277 func (c ConfigLanguage) EnableMissingTranslationPlaceholders() bool {
278 return c.config.EnableMissingTranslationPlaceholders
279 }
280
281 func (c ConfigLanguage) PrintI18nWarnings() bool {
282 return c.config.PrintI18nWarnings
283 }
284
285 func (c ConfigLanguage) CreateTitle(s string) string {
286 return c.config.C.CreateTitle(s)
287 }
288
289 func (c ConfigLanguage) Pagination() config.Pagination {
290 return c.config.Pagination
291 }
292
293 func (c ConfigLanguage) StaticDirs() []string {
294 return c.config.staticDirs()
295 }
296
297 func (c ConfigLanguage) EnableEmoji() bool {
298 return c.config.EnableEmoji
299 }
300
301 func (c ConfigLanguage) ConfiguredDimensions() *sitesmatrix.ConfiguredDimensions {
302 return c.m.ConfiguredDimensions
303 }
304
305 func (c ConfigLanguage) DefaultContentsitesMatrix() *sitesmatrix.IntSets {
306 return c.m.DefaultContentSitesMatrix
307 }
308
309 func (c ConfigLanguage) AllSitesMatrix() *sitesmatrix.IntSets {
310 return c.m.AllSitesMatrix
311 }