Debian Codegraph @

hugolib/page__position.go

raw
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/common/hsync"
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 hsync.FuncResetter
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) Prev() page.Page {
56 return p.prev()
57 }
58
59 type pagePositionInSection struct {
60 *nextPrev
61 }
62
63 func (p pagePositionInSection) NextInSection() page.Page {
64 return p.next()
65 }
66
67 func (p pagePositionInSection) PrevInSection() page.Page {
68 return p.prev()
69 }