Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename DefaultPageSize => PagerSize #12582

Merged
merged 2 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/allconfig/allconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ func (c *Config) CompileConfig(logger loggers.Logger) error {

// Legacy paginate values.
if c.Paginate != 0 {
hugo.Deprecate("site config key paginate", "Use paginator.defaultPageSize instead.", "v0.128.0")
c.Pagination.DefaultPageSize = c.Paginate
hugo.Deprecate("site config key paginate", "Use paginator.pagerSize instead.", "v0.128.0")
c.Pagination.PagerSize = c.Paginate
}

if c.PaginatePath != "" {
Expand Down
12 changes: 6 additions & 6 deletions config/allconfig/allconfig_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ func TestPaginationConfigOld(t *testing.T) {
confDe := b.H.Sites[1].Conf.Pagination()

b.Assert(confEn.Path, qt.Equals, "page-en")
b.Assert(confEn.DefaultPageSize, qt.Equals, 10)
b.Assert(confEn.PagerSize, qt.Equals, 10)
b.Assert(confDe.Path, qt.Equals, "page-de")
b.Assert(confDe.DefaultPageSize, qt.Equals, 20)
b.Assert(confDe.PagerSize, qt.Equals, 20)
}

func TestPaginationConfigNew(t *testing.T) {
Expand All @@ -133,7 +133,7 @@ func TestPaginationConfigNew(t *testing.T) {
[languages.en]
weight = 1
[languages.en.pagination]
defaultPageSize = 20
pagerSize = 20
[languages.de]
weight = 2
[languages.de.pagination]
Expand All @@ -147,9 +147,9 @@ func TestPaginationConfigNew(t *testing.T) {
confDe := b.H.Sites[1].Conf.Pagination()

b.Assert(confEn.Path, qt.Equals, "page")
b.Assert(confEn.DefaultPageSize, qt.Equals, 20)
b.Assert(confEn.PagerSize, qt.Equals, 20)
b.Assert(confDe.Path, qt.Equals, "page-de")
b.Assert(confDe.DefaultPageSize, qt.Equals, 10)
b.Assert(confDe.PagerSize, qt.Equals, 10)
}

func TestPaginationConfigDisableAliases(t *testing.T) {
Expand All @@ -158,7 +158,7 @@ func TestPaginationConfigDisableAliases(t *testing.T) {
disableKinds = ["taxonomy", "term"]
[pagination]
disableAliases = true
defaultPageSize = 2
pagerSize = 2
-- layouts/_default/list.html --
{{ $paginator := .Paginate site.RegularPages }}
{{ template "_internal/pagination.html" . }}
Expand Down
4 changes: 2 additions & 2 deletions config/allconfig/alldecoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ var allDecoderSetups = map[string]decodeWeight{
key: "pagination",
decode: func(d decodeWeight, p decodeConfig) error {
p.c.Pagination = config.Pagination{
DefaultPageSize: 10,
Path: "page",
PagerSize: 10,
Path: "page",
}
if p.p.IsSet(d.key) {
if err := mapstructure.WeakDecode(p.p.Get(d.key), &p.c.Pagination); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions config/commonConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ func DecodeServer(cfg Provider) (Server, error) {

// Pagination configures the pagination behavior.
type Pagination struct {
// Default number of elements per page in pagination.
DefaultPageSize int
// Default number of elements per pager in pagination.
PagerSize int

// The path element used during pagination.
Path string
Expand Down
10 changes: 9 additions & 1 deletion resources/page/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"math"
"reflect"

"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/config"

"github.com/spf13/cast"
Expand Down Expand Up @@ -194,7 +195,14 @@ func (p *Paginator) Pagers() pagers {
}

// PageSize returns the size of each paginator page.
// Deprecated: Use PagerSize instead.
func (p *Paginator) PageSize() int {
hugo.Deprecate("PageSize", "Use PagerSize instead.", "v0.128.0")
return p.size
}

// PagerSize returns the size of each paginator page.
func (p *Paginator) PagerSize() int {
return p.size
}

Expand Down Expand Up @@ -263,7 +271,7 @@ func splitPageGroups(pageGroups PagesGroup, size int) []paginatedElement {

func ResolvePagerSize(conf config.AllProvider, options ...any) (int, error) {
if len(options) == 0 {
return conf.Pagination().DefaultPageSize, nil
return conf.Pagination().PagerSize, nil
}

if len(options) > 1 {
Expand Down
6 changes: 3 additions & 3 deletions resources/page/pagination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func doTestPages(t *testing.T, paginator *Paginator) {

c.Assert(len(paginatorPages), qt.Equals, 5)
c.Assert(paginator.TotalNumberOfElements(), qt.Equals, 21)
c.Assert(paginator.PageSize(), qt.Equals, 5)
c.Assert(paginator.PagerSize(), qt.Equals, 5)
c.Assert(paginator.TotalPages(), qt.Equals, 5)

first := paginatorPages[0]
Expand Down Expand Up @@ -172,7 +172,7 @@ func doTestPagerNoPages(t *testing.T, paginator *Paginator) {
c := qt.New(t)
c.Assert(len(paginatorPages), qt.Equals, 1)
c.Assert(paginator.TotalNumberOfElements(), qt.Equals, 0)
c.Assert(paginator.PageSize(), qt.Equals, 5)
c.Assert(paginator.PagerSize(), qt.Equals, 5)
c.Assert(paginator.TotalPages(), qt.Equals, 0)

// pageOne should be nothing but the first
Expand All @@ -187,7 +187,7 @@ func doTestPagerNoPages(t *testing.T, paginator *Paginator) {
c.Assert(pageOne.TotalNumberOfElements(), qt.Equals, 0)
c.Assert(pageOne.TotalPages(), qt.Equals, 0)
c.Assert(pageOne.PageNumber(), qt.Equals, 1)
c.Assert(pageOne.PageSize(), qt.Equals, 5)
c.Assert(pageOne.PagerSize(), qt.Equals, 5)
}

func TestProbablyEqualPageLists(t *testing.T) {
Expand Down
Loading