site.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
---
site.go (9674B)
---
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 page
15
16 import (
17 "time"
18
19 "github.com/gohugoio/hugo/common/maps"
20 "github.com/gohugoio/hugo/config/privacy"
21 "github.com/gohugoio/hugo/config/services"
22 "github.com/gohugoio/hugo/identity"
23
24 "github.com/gohugoio/hugo/config"
25
26 "github.com/gohugoio/hugo/common/hugo"
27 "github.com/gohugoio/hugo/langs"
28 "github.com/gohugoio/hugo/navigation"
29 )
30
31 // Site represents a site. There can be multiple sites in a multilingual setup.
32 type Site interface {
33 // Returns the Language configured for this Site.
34 Language() *langs.Language
35
36 // Returns all the languages configured for all sites.
37 Languages() langs.Languages
38
39 GetPage(ref ...string) (Page, error)
40
41 // AllPages returns all pages for all languages.
42 AllPages() Pages
43
44 // Returns all the regular Pages in this Site.
45 RegularPages() Pages
46
47 // Returns all Pages in this Site.
48 Pages() Pages
49
50 // Returns all the top level sections.
51 Sections() Pages
52
53 // A shortcut to the home
54 Home() Page
55
56 // Returns the server port.
57 ServerPort() int
58
59 // Returns the configured title for this Site.
60 Title() string
61
62 // Deprecated: Use .Language.LanguageCode instead.
63 LanguageCode() string
64
65 // Returns the configured copyright information for this Site.
66 Copyright() string
67
68 // Returns all Sites for all languages.
69 Sites() Sites
70
71 // Returns Site currently rendering.
72 Current() Site
73
74 // Returns a struct with some information about the build.
75 Hugo() hugo.HugoInfo
76
77 // Returns the BaseURL for this Site.
78 BaseURL() string
79
80 // Returns a taxonomy map.
81 Taxonomies() TaxonomyList
82
83 // Deprecated: Use .Lastmod instead.
84 LastChange() time.Time
85
86 // Returns the last modification date of the content.
87 Lastmod() time.Time
88
89 // Returns the Menus for this site.
90 Menus() navigation.Menus
91
92 // The main sections in the site.
93 MainSections() []string
94
95 // Returns the Params configured for this site.
96 Params() maps.Params
97
98 // Param is a convenience method to do lookups in Params.
99 Param(key any) (any, error)
100
101 // Returns a map of all the data inside /data.
102 Data() map[string]any
103
104 // Returns the site config.
105 Config() SiteConfig
106
107 // Deprecated: Use taxonomies instead.
108 Author() map[string]any
109
110 // Deprecated: Use taxonomies instead.
111 Authors() AuthorList
112
113 // Deprecated: Use .Site.Params instead.
114 Social() map[string]string
115
116 // BuildDrafts is deprecated and will be removed in a future release.
117 BuildDrafts() bool
118
119 // Deprecated: Use hugo.IsMultilingual instead.
120 IsMultiLingual() bool
121
122 // LanguagePrefix returns the language prefix for this site.
123 LanguagePrefix() string
124
125 maps.StoreProvider
126
127 // For internal use only.
128 // This will panic if the site is not fully initialized.
129 // This is typically used to inform the user in the content adapter templates,
130 // as these are executed before all the page collections etc. are ready to use.
131 CheckReady()
132 }
133
134 // Sites represents an ordered list of sites (languages).
135 type Sites []Site
136
137 // Deprecated: Use .Sites.Default instead.
138 func (s Sites) First() Site {
139 hugo.Deprecate(".Sites.First", "Use .Sites.Default instead.", "v0.127.0")
140 return s.Default()
141 }
142
143 // Default is a convenience method to get the site corresponding to the default
144 // content language.
145 func (s Sites) Default() Site {
146 if len(s) == 0 {
147 return nil
148 }
149 return s[0]
150 }
151
152 // Some additional interfaces implemented by siteWrapper that's not on Site.
153 var _ identity.ForEeachIdentityByNameProvider = (*siteWrapper)(nil)
154
155 type siteWrapper struct {
156 s Site
157 }
158
159 func WrapSite(s Site) Site {
160 if s == nil {
161 panic("Site is nil")
162 }
163 return &siteWrapper{s: s}
164 }
165
166 func (s *siteWrapper) Key() string {
167 return s.s.Language().Lang
168 }
169
170 // Deprecated: Use .Site.Params instead.
171 func (s *siteWrapper) Social() map[string]string {
172 return s.s.Social()
173 }
174
175 // Deprecated: Use taxonomies instead.
176 func (s *siteWrapper) Author() map[string]any {
177 return s.s.Author()
178 }
179
180 // Deprecated: Use taxonomies instead.
181 func (s *siteWrapper) Authors() AuthorList {
182 return s.s.Authors()
183 }
184
185 func (s *siteWrapper) GetPage(ref ...string) (Page, error) {
186 return s.s.GetPage(ref...)
187 }
188
189 func (s *siteWrapper) Language() *langs.Language {
190 return s.s.Language()
191 }
192
193 func (s *siteWrapper) Languages() langs.Languages {
194 return s.s.Languages()
195 }
196
197 func (s *siteWrapper) AllPages() Pages {
198 return s.s.AllPages()
199 }
200
201 func (s *siteWrapper) RegularPages() Pages {
202 return s.s.RegularPages()
203 }
204
205 func (s *siteWrapper) Pages() Pages {
206 return s.s.Pages()
207 }
208
209 func (s *siteWrapper) Sections() Pages {
210 return s.s.Sections()
211 }
212
213 func (s *siteWrapper) Home() Page {
214 return s.s.Home()
215 }
216
217 func (s *siteWrapper) ServerPort() int {
218 return s.s.ServerPort()
219 }
220
221 func (s *siteWrapper) Title() string {
222 return s.s.Title()
223 }
224
225 func (s *siteWrapper) LanguageCode() string {
226 return s.s.LanguageCode()
227 }
228
229 func (s *siteWrapper) Copyright() string {
230 return s.s.Copyright()
231 }
232
233 func (s *siteWrapper) Sites() Sites {
234 return s.s.Sites()
235 }
236
237 func (s *siteWrapper) Current() Site {
238 return s.s.Current()
239 }
240
241 func (s *siteWrapper) Config() SiteConfig {
242 return s.s.Config()
243 }
244
245 func (s *siteWrapper) Hugo() hugo.HugoInfo {
246 return s.s.Hugo()
247 }
248
249 func (s *siteWrapper) BaseURL() string {
250 return s.s.BaseURL()
251 }
252
253 func (s *siteWrapper) Taxonomies() TaxonomyList {
254 return s.s.Taxonomies()
255 }
256
257 // Deprecated: Use .Site.Lastmod instead.
258 func (s *siteWrapper) LastChange() time.Time {
259 return s.s.LastChange()
260 }
261
262 func (s *siteWrapper) Lastmod() time.Time {
263 return s.s.Lastmod()
264 }
265
266 func (s *siteWrapper) Menus() navigation.Menus {
267 return s.s.Menus()
268 }
269
270 func (s *siteWrapper) MainSections() []string {
271 return s.s.MainSections()
272 }
273
274 func (s *siteWrapper) Params() maps.Params {
275 return s.s.Params()
276 }
277
278 func (s *siteWrapper) Param(key any) (any, error) {
279 return s.s.Param(key)
280 }
281
282 func (s *siteWrapper) Data() map[string]any {
283 return s.s.Data()
284 }
285
286 func (s *siteWrapper) BuildDrafts() bool {
287 return s.s.BuildDrafts()
288 }
289
290 // Deprecated: Use hugo.IsMultilingual instead.
291 func (s *siteWrapper) IsMultiLingual() bool {
292 return s.s.IsMultiLingual()
293 }
294
295 func (s *siteWrapper) LanguagePrefix() string {
296 return s.s.LanguagePrefix()
297 }
298
299 func (s *siteWrapper) Store() *maps.Scratch {
300 return s.s.Store()
301 }
302
303 // For internal use only.
304 func (s *siteWrapper) ForEeachIdentityByName(name string, f func(identity.Identity) bool) {
305 s.s.(identity.ForEeachIdentityByNameProvider).ForEeachIdentityByName(name, f)
306 }
307
308 // For internal use only.
309 func (s *siteWrapper) CheckReady() {
310 s.s.CheckReady()
311 }
312
313 type testSite struct {
314 h hugo.HugoInfo
315 l *langs.Language
316 }
317
318 // Deprecated: Use taxonomies instead.
319 func (s testSite) Author() map[string]any {
320 return nil
321 }
322
323 // Deprecated: Use taxonomies instead.
324 func (s testSite) Authors() AuthorList {
325 return AuthorList{}
326 }
327
328 // Deprecated: Use .Site.Params instead.
329 func (s testSite) Social() map[string]string {
330 return make(map[string]string)
331 }
332
333 func (t testSite) Hugo() hugo.HugoInfo {
334 return t.h
335 }
336
337 func (t testSite) ServerPort() int {
338 return 1313
339 }
340
341 // Deprecated: Use .Site.Lastmod instead.
342 func (testSite) LastChange() (t time.Time) {
343 return
344 }
345
346 func (testSite) Lastmod() (t time.Time) {
347 return
348 }
349
350 func (t testSite) Title() string {
351 return "foo"
352 }
353
354 func (t testSite) LanguageCode() string {
355 return t.l.Lang
356 }
357
358 func (t testSite) Copyright() string {
359 return ""
360 }
361
362 func (t testSite) Sites() Sites {
363 return nil
364 }
365
366 func (t testSite) Sections() Pages {
367 return nil
368 }
369
370 func (t testSite) GetPage(ref ...string) (Page, error) {
371 return nil, nil
372 }
373
374 func (t testSite) Current() Site {
375 return t
376 }
377
378 func (s testSite) LanguagePrefix() string {
379 return ""
380 }
381
382 func (t testSite) Languages() langs.Languages {
383 return nil
384 }
385
386 func (t testSite) MainSections() []string {
387 return nil
388 }
389
390 func (t testSite) Language() *langs.Language {
391 return t.l
392 }
393
394 func (t testSite) Home() Page {
395 return nil
396 }
397
398 func (t testSite) Pages() Pages {
399 return nil
400 }
401
402 func (t testSite) AllPages() Pages {
403 return nil
404 }
405
406 func (t testSite) RegularPages() Pages {
407 return nil
408 }
409
410 func (t testSite) Menus() navigation.Menus {
411 return nil
412 }
413
414 func (t testSite) Taxonomies() TaxonomyList {
415 return nil
416 }
417
418 func (t testSite) BaseURL() string {
419 return ""
420 }
421
422 func (t testSite) Params() maps.Params {
423 return nil
424 }
425
426 func (t testSite) Data() map[string]any {
427 return nil
428 }
429
430 func (s testSite) Config() SiteConfig {
431 return SiteConfig{}
432 }
433
434 func (s testSite) BuildDrafts() bool {
435 return false
436 }
437
438 // Deprecated: Use hugo.IsMultilingual instead.
439 func (s testSite) IsMultiLingual() bool {
440 return false
441 }
442
443 func (s testSite) Param(key any) (any, error) {
444 return nil, nil
445 }
446
447 func (s testSite) Store() *maps.Scratch {
448 return maps.NewScratch()
449 }
450
451 func (s testSite) CheckReady() {
452 }
453
454 // NewDummyHugoSite creates a new minimal test site.
455 func NewDummyHugoSite(conf config.AllProvider) Site {
456 return testSite{
457 h: hugo.NewInfo(conf, nil),
458 l: &langs.Language{
459 Lang: "en",
460 },
461 }
462 }
463
464 // SiteConfig holds the config in site.Config.
465 type SiteConfig struct {
466 // This contains all privacy related settings that can be used to
467 // make the YouTube template etc. GDPR compliant.
468 Privacy privacy.Config
469
470 // Services contains config for services such as Google Analytics etc.
471 Services services.Config
472 }