configlanguage.go - hugo - [fork] hugo port for 9front
HTML git clone https://git.drkhsh.at/hugo.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
configlanguage.go (6163B)
---
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/identity"
23 "github.com/gohugoio/hugo/langs"
24 )
25
26 type ConfigLanguage struct {
27 config *Config
28 baseConfig config.BaseConfig
29
30 m *Configs
31 language *langs.Language
32 }
33
34 func (c ConfigLanguage) Language() *langs.Language {
35 return c.language
36 }
37
38 func (c ConfigLanguage) Languages() langs.Languages {
39 return c.m.Languages
40 }
41
42 func (c ConfigLanguage) LanguagesDefaultFirst() langs.Languages {
43 return c.m.LanguagesDefaultFirst
44 }
45
46 func (c ConfigLanguage) PathParser() *paths.PathParser {
47 return c.m.ContentPathParser
48 }
49
50 func (c ConfigLanguage) LanguagePrefix() string {
51 if c.DefaultContentLanguageInSubdir() && c.DefaultContentLanguage() == c.Language().Lang {
52 return c.Language().Lang
53 }
54
55 if !c.IsMultilingual() || c.DefaultContentLanguage() == c.Language().Lang {
56 return ""
57 }
58 return c.Language().Lang
59 }
60
61 func (c ConfigLanguage) BaseURL() urls.BaseURL {
62 return c.config.C.BaseURL
63 }
64
65 func (c ConfigLanguage) BaseURLLiveReload() urls.BaseURL {
66 return c.config.C.BaseURLLiveReload
67 }
68
69 func (c ConfigLanguage) Environment() string {
70 return c.config.Environment
71 }
72
73 func (c ConfigLanguage) IsMultihost() bool {
74 if len(c.m.Languages)-len(c.config.C.DisabledLanguages) <= 1 {
75 return false
76 }
77 return c.m.IsMultihost
78 }
79
80 func (c ConfigLanguage) FastRenderMode() bool {
81 return c.config.Internal.FastRenderMode
82 }
83
84 func (c ConfigLanguage) IsMultilingual() bool {
85 return len(c.m.Languages) > 1
86 }
87
88 func (c ConfigLanguage) TemplateMetrics() bool {
89 return c.config.TemplateMetrics
90 }
91
92 func (c ConfigLanguage) TemplateMetricsHints() bool {
93 return c.config.TemplateMetricsHints
94 }
95
96 func (c ConfigLanguage) IsLangDisabled(lang string) bool {
97 return c.config.C.DisabledLanguages[lang]
98 }
99
100 func (c ConfigLanguage) IgnoredLogs() map[string]bool {
101 return c.config.C.IgnoredLogs
102 }
103
104 func (c ConfigLanguage) NoBuildLock() bool {
105 return c.config.NoBuildLock
106 }
107
108 func (c ConfigLanguage) NewContentEditor() string {
109 return c.config.NewContentEditor
110 }
111
112 func (c ConfigLanguage) Timeout() time.Duration {
113 return c.config.C.Timeout
114 }
115
116 func (c ConfigLanguage) BaseConfig() config.BaseConfig {
117 return c.baseConfig
118 }
119
120 func (c ConfigLanguage) Dirs() config.CommonDirs {
121 return c.config.CommonDirs
122 }
123
124 func (c ConfigLanguage) DirsBase() config.CommonDirs {
125 return c.m.Base.CommonDirs
126 }
127
128 func (c ConfigLanguage) WorkingDir() string {
129 return c.m.Base.WorkingDir
130 }
131
132 func (c ConfigLanguage) Quiet() bool {
133 return c.m.Base.Internal.Quiet
134 }
135
136 func (c ConfigLanguage) Watching() bool {
137 return c.m.Base.Internal.Watch
138 }
139
140 func (c ConfigLanguage) NewIdentityManager(name string, opts ...identity.ManagerOption) identity.Manager {
141 if !c.Watching() {
142 return identity.NopManager
143 }
144 return identity.NewManager(name, opts...)
145 }
146
147 func (c ConfigLanguage) ContentTypes() config.ContentTypesProvider {
148 return c.config.ContentTypes.Config
149 }
150
151 // GetConfigSection is mostly used in tests. The switch statement isn't complete, but what's in use.
152 func (c ConfigLanguage) GetConfigSection(s string) any {
153 switch s {
154 case "security":
155 return c.config.Security
156 case "build":
157 return c.config.Build
158 case "frontmatter":
159 return c.config.Frontmatter
160 case "caches":
161 return c.config.Caches
162 case "markup":
163 return c.config.Markup
164 case "mediaTypes":
165 return c.config.MediaTypes.Config
166 case "outputFormats":
167 return c.config.OutputFormats.Config
168 case "permalinks":
169 return c.config.Permalinks
170 case "minify":
171 return c.config.Minify
172 case "allModules":
173 return c.m.Modules
174 case "deployment":
175 return c.config.Deployment
176 case "httpCacheCompiled":
177 return c.config.C.HTTPCache
178 default:
179 panic("not implemented: " + s)
180 }
181 }
182
183 func (c ConfigLanguage) GetConfig() any {
184 return c.config
185 }
186
187 func (c ConfigLanguage) CanonifyURLs() bool {
188 return c.config.CanonifyURLs
189 }
190
191 func (c ConfigLanguage) IsUglyURLs(section string) bool {
192 return c.config.C.IsUglyURLSection(section)
193 }
194
195 func (c ConfigLanguage) IgnoreFile(s string) bool {
196 return c.config.C.IgnoreFile(s)
197 }
198
199 func (c ConfigLanguage) DisablePathToLower() bool {
200 return c.config.DisablePathToLower
201 }
202
203 func (c ConfigLanguage) RemovePathAccents() bool {
204 return c.config.RemovePathAccents
205 }
206
207 func (c ConfigLanguage) DefaultContentLanguage() string {
208 return c.config.DefaultContentLanguage
209 }
210
211 func (c ConfigLanguage) DefaultContentLanguageInSubdir() bool {
212 return c.config.DefaultContentLanguageInSubdir
213 }
214
215 func (c ConfigLanguage) SummaryLength() int {
216 return c.config.SummaryLength
217 }
218
219 func (c ConfigLanguage) BuildExpired() bool {
220 return c.config.BuildExpired
221 }
222
223 func (c ConfigLanguage) BuildFuture() bool {
224 return c.config.BuildFuture
225 }
226
227 func (c ConfigLanguage) BuildDrafts() bool {
228 return c.config.BuildDrafts
229 }
230
231 func (c ConfigLanguage) Running() bool {
232 return c.config.Internal.Running
233 }
234
235 func (c ConfigLanguage) PrintUnusedTemplates() bool {
236 return c.config.PrintUnusedTemplates
237 }
238
239 func (c ConfigLanguage) EnableMissingTranslationPlaceholders() bool {
240 return c.config.EnableMissingTranslationPlaceholders
241 }
242
243 func (c ConfigLanguage) PrintI18nWarnings() bool {
244 return c.config.PrintI18nWarnings
245 }
246
247 func (c ConfigLanguage) CreateTitle(s string) string {
248 return c.config.C.CreateTitle(s)
249 }
250
251 func (c ConfigLanguage) Pagination() config.Pagination {
252 return c.config.Pagination
253 }
254
255 func (c ConfigLanguage) StaticDirs() []string {
256 return c.config.staticDirs()
257 }
258
259 func (c ConfigLanguage) EnableEmoji() bool {
260 return c.config.EnableEmoji
261 }