page__common.go (3747B)
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 hugolib 15 16 import ( 17 "sync" 18 19 "github.com/bep/gitmap" 20 "github.com/gohugoio/hugo/common/maps" 21 "github.com/gohugoio/hugo/compare" 22 "github.com/gohugoio/hugo/lazy" 23 "github.com/gohugoio/hugo/navigation" 24 "github.com/gohugoio/hugo/output" 25 "github.com/gohugoio/hugo/resources/page" 26 "github.com/gohugoio/hugo/resources/resource" 27 ) 28 29 type treeRefProvider interface { 30 getTreeRef() *contentTreeRef 31 } 32 33 func (p *pageCommon) getTreeRef() *contentTreeRef { 34 return p.treeRef 35 } 36 37 type nextPrevProvider interface { 38 getNextPrev() *nextPrev 39 } 40 41 func (p *pageCommon) getNextPrev() *nextPrev { 42 return p.posNextPrev 43 } 44 45 type nextPrevInSectionProvider interface { 46 getNextPrevInSection() *nextPrev 47 } 48 49 func (p *pageCommon) getNextPrevInSection() *nextPrev { 50 return p.posNextPrevSection 51 } 52 53 type pageCommon struct { 54 s *Site 55 m *pageMeta 56 57 bucket *pagesMapBucket 58 treeRef *contentTreeRef 59 60 // Lazily initialized dependencies. 61 init *lazy.Init 62 63 // Store holds state that survives server rebuilds. 64 store *maps.Scratch 65 66 // All of these represents the common parts of a page.Page 67 maps.Scratcher 68 navigation.PageMenusProvider 69 page.AuthorProvider 70 page.AlternativeOutputFormatsProvider 71 page.ChildCareProvider 72 page.FileProvider 73 page.GetPageProvider 74 page.GitInfoProvider 75 page.InSectionPositioner 76 page.OutputFormatsProvider 77 page.PageMetaProvider 78 page.Positioner 79 page.RawContentProvider 80 page.RelatedKeywordsProvider 81 page.RefProvider 82 page.ShortcodeInfoProvider 83 page.SitesProvider 84 page.TranslationsProvider 85 page.TreeProvider 86 resource.LanguageProvider 87 resource.ResourceDataProvider 88 resource.ResourceMetaProvider 89 resource.ResourceParamsProvider 90 resource.ResourceTypeProvider 91 resource.MediaTypeProvider 92 resource.TranslationKeyProvider 93 compare.Eqer 94 95 // Describes how paths and URLs for this page and its descendants 96 // should look like. 97 targetPathDescriptor page.TargetPathDescriptor 98 99 layoutDescriptor output.LayoutDescriptor 100 layoutDescriptorInit sync.Once 101 102 // The parsed page content. 103 pageContent 104 105 // Keeps track of the shortcodes on a page. 106 shortcodeState *shortcodeHandler 107 108 // Set if feature enabled and this is in a Git repo. 109 gitInfo *gitmap.GitInfo 110 codeowners []string 111 112 // Positional navigation 113 posNextPrev *nextPrev 114 posNextPrevSection *nextPrev 115 116 // Menus 117 pageMenus *pageMenus 118 119 // Internal use 120 page.InternalDependencies 121 122 // The children. Regular pages will have none. 123 *pagePages 124 125 // Any bundled resources 126 resources resource.Resources 127 resourcesInit sync.Once 128 resourcesPublishInit sync.Once 129 130 translations page.Pages 131 allTranslations page.Pages 132 133 // Calculated an cached translation mapping key 134 translationKey string 135 translationKeyInit sync.Once 136 137 // Will only be set for bundled pages. 138 parent *pageState 139 140 // Set in fast render mode to force render a given page. 141 forceRender bool 142 } 143 144 func (p *pageCommon) Store() *maps.Scratch { 145 return p.store 146 } 147 148 type pagePages struct { 149 pagesInit sync.Once 150 pages page.Pages 151 152 regularPagesInit sync.Once 153 regularPages page.Pages 154 regularPagesRecursiveInit sync.Once 155 regularPagesRecursive page.Pages 156 }