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) IgnoreTailwindCSSSecurityError() bool {
95 return c.config.InternalExternal.IgnoreTailwindCSSSecurityError
96 }
97
98 func (c ConfigLanguage) IsMultilingual() bool {
99 return len(c.m.Languages) > 1
100 }
101
102 func (c ConfigLanguage) TemplateMetrics() bool {
103 return c.config.TemplateMetrics
104 }
105
106 func (c ConfigLanguage) TemplateMetricsHints() bool {
107 return c.config.TemplateMetricsHints
108 }
109
110 func (c ConfigLanguage) IsLangDisabled(lang string) bool {
111 return c.config.C.DisabledLanguages[lang]
112 }
113
114 func (c ConfigLanguage) IsKindEnabled(kind string) bool {
115 return !c.config.C.DisabledKinds[kind]
116 }
117
118 func (c ConfigLanguage) IgnoredLogs() map[string]bool {
119 return c.config.C.IgnoredLogs
120 }
121
122 func (c ConfigLanguage) NoBuildLock() bool {
123 return c.config.NoBuildLock
124 }
125
126 func (c ConfigLanguage) NewContentEditor() string {
127 return c.config.NewContentEditor
128 }
129
130 func (c ConfigLanguage) Timeout() time.Duration {
131 return c.config.C.Timeout
132 }
133
134 func (c ConfigLanguage) BaseConfig() config.BaseConfig {
135 return c.baseConfig
136 }
137
138 func (c ConfigLanguage) FileCaches() any {
139 return c.m.FileCaches
140 }
141
142 func (c ConfigLanguage) Dirs() config.CommonDirs {
143 return c.config.CommonDirs
144 }
145
146 func (c ConfigLanguage) DirsBase() config.CommonDirs {
147 return c.m.Base.CommonDirs
148 }
149
150 func (c ConfigLanguage) WorkingDir() string {
151 return c.m.Base.WorkingDir
152 }
153
154 func (c ConfigLanguage) CacheDirMisc() string {
155 return c.config.Caches.CacheDirMisc()
156 }
157
158 func (c ConfigLanguage) Quiet() bool {
159 return c.m.Base.Internal.Quiet
160 }
161
162 func (c ConfigLanguage) Watching() bool {
163 return c.m.Base.Internal.Watch
164 }
165
166 func (c ConfigLanguage) NewIdentityManager(opts ...identity.ManagerOption) identity.Manager {
167 if !c.Watching() {
168 return identity.NopManager
169 }
170 return identity.NewManager(opts...)
171 }
172
173 func (c ConfigLanguage) ContentTypes() config.ContentTypesProvider {
174 return c.config.ContentTypes.Config
175 }
176
177 // GetConfigSection is mostly used in tests. The switch statement isn't complete, but what's in use.
178 func (c ConfigLanguage) GetConfigSection(s string) any {
179 switch s {
180 case "security":
181 return c.config.Security
182 case "build":
183 return c.config.Build
184 case "cascade":
185 return c.config.Cascade
186 case "frontmatter":
187 return c.config.Frontmatter
188 case "caches":
189 return c.config.Caches
190 case "markup":
191 return c.config.Markup
192 case "module":
193 return c.config.Module
194 case "mediaTypes":
195 return c.config.MediaTypes.Config
196 case "outputFormats":
197 return c.config.OutputFormats.Config
198 case "roles":
199 return c.config.Roles.Config
200 case "versions":
201 return c.config.Versions.Config
202 case "permalinks":
203 return c.config.Permalinks
204 case "minify":
205 return c.config.Minify
206 case "allModules":
207 return c.m.Modules
208 case "deployment":
209 return c.config.Deployment
210 case "httpCacheCompiled":
211 return c.config.C.HTTPCache
212 default:
213 panic("not implemented: " + s)
214 }
215 }
216
217 func (c ConfigLanguage) GetConfig() any {
218 return c.config
219 }
220
221 func (c ConfigLanguage) CanonifyURLs() bool {
222 return c.config.CanonifyURLs
223 }
224
225 func (c ConfigLanguage) IsUglyURLs(section string) bool {
226 return c.config.C.IsUglyURLSection(section)
227 }
228
229 func (c ConfigLanguage) IgnoreFile(s string) bool {
230 return c.config.C.IgnoreFile(s)
231 }
232
233 func (c ConfigLanguage) DisablePathToLower() bool {
234 return c.config.DisablePathToLower
235 }
236
237 func (c ConfigLanguage) RemovePathAccents() bool {
238 return c.config.RemovePathAccents
239 }
240
241 func (c ConfigLanguage) DefaultContentLanguage() string {
242 return c.config.DefaultContentLanguage
243 }
244
245 func (c ConfigLanguage) DefaultContentLanguageInSubdir() bool {
246 return c.config.DefaultContentLanguageInSubdir
247 }
248
249 func (c ConfigLanguage) DefaultContentRoleInSubdir() bool {
250 return c.config.DefaultContentRoleInSubdir
251 }
252
253 func (c ConfigLanguage) DefaultContentVersionInSubdir() bool {
254 return c.config.DefaultContentVersionInSubdir
255 }
256
257 func (c ConfigLanguage) SummaryLength() int {
258 return c.config.SummaryLength
259 }
260
261 func (c ConfigLanguage) BuildExpired() bool {
262 return c.config.BuildExpired
263 }
264
265 func (c ConfigLanguage) BuildFuture() bool {
266 return c.config.BuildFuture
267 }
268
269 func (c ConfigLanguage) BuildDrafts() bool {
270 return c.config.BuildDrafts
271 }
272
273 func (c ConfigLanguage) Running() bool {
274 return c.config.Internal.Running
275 }
276
277 func (c ConfigLanguage) PrintUnusedTemplates() bool {
278 return c.config.PrintUnusedTemplates
279 }
280
281 func (c ConfigLanguage) EnableMissingTranslationPlaceholders() bool {
282 return c.config.EnableMissingTranslationPlaceholders
283 }
284
285 func (c ConfigLanguage) PrintI18nWarnings() bool {
286 return c.config.PrintI18nWarnings
287 }
288
289 func (c ConfigLanguage) CreateTitle(s string) string {
290 return c.config.C.CreateTitle(s)
291 }
292
293 func (c ConfigLanguage) Pagination() config.Pagination {
294 return c.config.Pagination
295 }
296
297 func (c ConfigLanguage) StaticDirs() []string {
298 return c.config.staticDirs()
299 }
300
301 func (c ConfigLanguage) EnableEmoji() bool {
302 return c.config.EnableEmoji
303 }
304
305 func (c ConfigLanguage) ConfiguredDimensions() *sitesmatrix.ConfiguredDimensions {
306 return c.m.ConfiguredDimensions
307 }
308
309 func (c ConfigLanguage) DefaultContentsitesMatrix() *sitesmatrix.IntSets {
310 return c.m.DefaultContentSitesMatrix
311 }
312
313 func (c ConfigLanguage) AllSitesMatrix() *sitesmatrix.IntSets {
314 return c.m.AllSitesMatrix
315 }