github.com/linchen2chris/hugo@v0.0.0-20230307053224-cec209389705/hugolib/page__position.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 hugolib 15 16 import ( 17 "context" 18 19 "github.com/gohugoio/hugo/lazy" 20 "github.com/gohugoio/hugo/resources/page" 21 ) 22 23 func newPagePosition(n *nextPrev) pagePosition { 24 return pagePosition{nextPrev: n} 25 } 26 27 func newPagePositionInSection(n *nextPrev) pagePositionInSection { 28 return pagePositionInSection{nextPrev: n} 29 } 30 31 type nextPrev struct { 32 init *lazy.Init 33 prevPage page.Page 34 nextPage page.Page 35 } 36 37 func (n *nextPrev) next() page.Page { 38 n.init.Do(context.Background()) 39 return n.nextPage 40 } 41 42 func (n *nextPrev) prev() page.Page { 43 n.init.Do(context.Background()) 44 return n.prevPage 45 } 46 47 type pagePosition struct { 48 *nextPrev 49 } 50 51 func (p pagePosition) Next() page.Page { 52 return p.next() 53 } 54 55 func (p pagePosition) NextPage() page.Page { 56 return p.Next() 57 } 58 59 func (p pagePosition) Prev() page.Page { 60 return p.prev() 61 } 62 63 func (p pagePosition) PrevPage() page.Page { 64 return p.Prev() 65 } 66 67 type pagePositionInSection struct { 68 *nextPrev 69 } 70 71 func (p pagePositionInSection) NextInSection() page.Page { 72 return p.next() 73 } 74 75 func (p pagePositionInSection) PrevInSection() page.Page { 76 return p.prev() 77 }