github.com/neohugo/neohugo@v0.123.8/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/neohugo/neohugo/common/neohugo"
    20  	"github.com/neohugo/neohugo/lazy"
    21  	"github.com/neohugo/neohugo/resources/page"
    22  )
    23  
    24  func newPagePosition(n *nextPrev) pagePosition {
    25  	return pagePosition{nextPrev: n}
    26  }
    27  
    28  func newPagePositionInSection(n *nextPrev) pagePositionInSection {
    29  	return pagePositionInSection{nextPrev: n}
    30  }
    31  
    32  type nextPrev struct {
    33  	init     *lazy.Init
    34  	prevPage page.Page
    35  	nextPage page.Page
    36  }
    37  
    38  func (n *nextPrev) next() page.Page {
    39  	// TODO may check error
    40  	//nolint
    41  	n.init.Do(context.Background())
    42  	return n.nextPage
    43  }
    44  
    45  func (n *nextPrev) prev() page.Page {
    46  	// TODO may check error
    47  	//nolint
    48  	n.init.Do(context.Background())
    49  	return n.prevPage
    50  }
    51  
    52  type pagePosition struct {
    53  	*nextPrev
    54  }
    55  
    56  func (p pagePosition) Next() page.Page {
    57  	return p.next()
    58  }
    59  
    60  // Deprecated: Use Next instead.
    61  func (p pagePosition) NextPage() page.Page {
    62  	neohugo.Deprecate(".Page.NextPage", "Use .Page.Next instead.", "v0.123.0")
    63  	return p.Next()
    64  }
    65  
    66  func (p pagePosition) Prev() page.Page {
    67  	return p.prev()
    68  }
    69  
    70  // Deprecated: Use Prev instead.
    71  func (p pagePosition) PrevPage() page.Page {
    72  	neohugo.Deprecate(".Page.PrevPage", "Use .Page.Prev instead.", "v0.123.0")
    73  	return p.Prev()
    74  }
    75  
    76  type pagePositionInSection struct {
    77  	*nextPrev
    78  }
    79  
    80  func (p pagePositionInSection) NextInSection() page.Page {
    81  	return p.next()
    82  }
    83  
    84  func (p pagePositionInSection) PrevInSection() page.Page {
    85  	return p.prev()
    86  }