github.com/graemephi/kahugo@v0.62.3-0.20211121071557-d78c0423784d/resources/page/site.go (about) 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 "html/template" 18 "time" 19 20 "github.com/gohugoio/hugo/common/maps" 21 22 "github.com/gohugoio/hugo/config" 23 24 "github.com/gohugoio/hugo/common/hugo" 25 "github.com/gohugoio/hugo/langs" 26 "github.com/gohugoio/hugo/navigation" 27 ) 28 29 // Site represents a site in the build. This is currently a very narrow interface, 30 // but the actual implementation will be richer, see hugolib.SiteInfo. 31 type Site interface { 32 Language() *langs.Language 33 RegularPages() Pages 34 Pages() Pages 35 IsServer() bool 36 ServerPort() int 37 Title() string 38 Sites() Sites 39 Hugo() hugo.Info 40 BaseURL() template.URL 41 Taxonomies() interface{} 42 LastChange() time.Time 43 Menus() navigation.Menus 44 Params() maps.Params 45 Data() map[string]interface{} 46 } 47 48 // Sites represents an ordered list of sites (languages). 49 type Sites []Site 50 51 // First is a convenience method to get the first Site, i.e. the main language. 52 func (s Sites) First() Site { 53 if len(s) == 0 { 54 return nil 55 } 56 return s[0] 57 } 58 59 type testSite struct { 60 h hugo.Info 61 l *langs.Language 62 } 63 64 func (t testSite) Hugo() hugo.Info { 65 return t.h 66 } 67 68 func (t testSite) ServerPort() int { 69 return 1313 70 } 71 72 func (testSite) LastChange() (t time.Time) { 73 return 74 } 75 76 func (t testSite) Title() string { 77 return "foo" 78 } 79 80 func (t testSite) Sites() Sites { 81 return nil 82 } 83 84 func (t testSite) IsServer() bool { 85 return false 86 } 87 88 func (t testSite) Language() *langs.Language { 89 return t.l 90 } 91 92 func (t testSite) Pages() Pages { 93 return nil 94 } 95 96 func (t testSite) RegularPages() Pages { 97 return nil 98 } 99 100 func (t testSite) Menus() navigation.Menus { 101 return nil 102 } 103 104 func (t testSite) Taxonomies() interface{} { 105 return nil 106 } 107 108 func (t testSite) BaseURL() template.URL { 109 return "" 110 } 111 112 func (t testSite) Params() maps.Params { 113 return nil 114 } 115 116 func (t testSite) Data() map[string]interface{} { 117 return nil 118 } 119 120 // NewDummyHugoSite creates a new minimal test site. 121 func NewDummyHugoSite(cfg config.Provider) Site { 122 return testSite{ 123 h: hugo.NewInfo(hugo.EnvironmentProduction), 124 l: langs.NewLanguage("en", cfg), 125 } 126 }