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

Add pagination support for home page, sections and taxonomies #750

Closed
wants to merge 1 commit into from

Conversation

bep
Copy link
Member

@bep bep commented Dec 28, 2014

Two new configuration properties, Paginate (default 0) and PaginatePath (default page) are added.

Setting paginate to a positive value will split the list pages for the home page, sections and taxonomies into chunks of size of the paginate property.

A .Paginator is provided to help building a pager menu.

There are two ways to configure a .Paginator:

  1. The simplest way is just to call .Paginator.Pages from a template. It will contain the pages for "that page" (.Data.Pages will (like today) contain all the pages).
  2. Select a sub-set of the pages with the available template functions and pass the slice to .Paginate : {{ range (.Paginate (where .Data.Pages "Type" "post")).Pages }}

NOTE: For a given Node, it's one of the options above. It's perfectly legitimate to iterate over the same pager more than once, but it's static and cannot change.

The .Paginator contains enough information to build a full-blown paginator interface.

The pages are built on the form (note: BLANK means no value, i.e. home page and page can be replaced by setting the PaginatePath ):

[SECTION/TAXONOMY/BLANK]/index.html
[SECTION/TAXONOMY/BLANK]/page/1/index.html => redirect to  [SECTION/TAXONOMY/BLANK]/index.html
[SECTION/TAXONOMY/BLANK]/page/2/index.html
....

Fixes #96

@bep bep force-pushed the feature/pagination branch 10 times, most recently from a44fac6 to 5a36b21 Compare December 30, 2014 14:03
@bep
Copy link
Member Author

bep commented Dec 30, 2014

@spf13 this should be pretty complete now. I might do something to improve integrationtesting and check on the performance characteristics (looks like just a slight overhead on my site), but it should work.

I set the default for the paginator setting to 0. In the future, maybe the default should be 10 or something, but then we should have some pagination templates built in.

See http://discuss.gohugo.io/t/pagination-implementation-feedback-appreciated/519/8 for more info.

I will write some documentation if this one goes into the wild.

@bep bep force-pushed the feature/pagination branch 2 times, most recently from 9b4c2a1 to b9062ac Compare December 30, 2014 21:02
@bep
Copy link
Member Author

bep commented Dec 30, 2014

Some kind tester found a issue that I will have to fix.

EDIT IN: issue fixed, but this can stay in test modus for a day or two, me thinks.

@bep bep force-pushed the feature/pagination branch 2 times, most recently from edd957e to e0a2f60 Compare January 1, 2015 23:07
@bep bep added the Enhancement label Jan 2, 2015
@anthonyfok anthonyfok added this to the v0.13 milestone Jan 21, 2015
@bep
Copy link
Member Author

bep commented Jan 25, 2015

I have an idea about how to improve this one. Will add to this PR.

@bep bep changed the title Add pagination support for sections and taxonomies Add pagination support for home page, sections and taxonomies Jan 25, 2015
@bep
Copy link
Member Author

bep commented Jan 25, 2015

Now it supports home page, sections and taxonomies -- and "all kinds of lists".

@bep bep force-pushed the feature/pagination branch 5 times, most recently from 9cac006 to 688d7fc Compare January 26, 2015 02:06
@spf13
Copy link
Contributor

spf13 commented Jan 26, 2015

This is pretty brilliant! Thanks for contributing this. It's been the most requested feature for the past year.

@bep bep force-pushed the feature/pagination branch 5 times, most recently from 040051c to dcea325 Compare January 26, 2015 11:04
@bep
Copy link
Member Author

bep commented Jan 26, 2015

Yes, I think it now has the right Hugo balance between simple. yet very powerful.

I will add docs later, and we should probably provide an internal template ala the ul-section here:

https://github.com/bjornerik/bepsays.com/blob/master/layouts/partials/pagination.html

(Bootstrap-compatible).

Feel free to merge, @spf13. Or I can do it myself if you do not object.

@spf13
Copy link
Contributor

spf13 commented Jan 26, 2015

Feel free to merge it.

Two new configuration properties, `Paginate` (default `0`) and `PaginatePath` (default `page`) are added.

Setting `paginate` to a positive value will split the list pages for the home page, sections and taxonomies into chunks of size of the `paginate` property.

A `.Paginator` is provided to help building a pager menu.

There are two ways to configure a `.Paginator`:

1. The simplest way is just to call `.Paginator.Pages` from a template. It will contain the pages for "that page" (`.Data.Pages` will (like today) contain all the pages).
2. Select a sub-set of the pages with the available template functions and pass the slice to `.Paginate` : `{{ range (.Paginate (where .Data.Pages "Type" "post")).Pages }}`

**NOTE:** For a given Node, it's one of the options above. It's perfectly legitimate to iterate over the same pager more than once, but it's static and cannot change.

The `.Paginator` contains enough information to build a full-blown paginator interface.

The pages are built on the form (note: BLANK means no value, i.e. home page):

```
[SECTION/TAXONOMY/BLANK]/index.html
[SECTION/TAXONOMY/BLANK]/page/1/index.html => redirect to  [SECTION/TAXONOMY/BLANK]/index.html
[SECTION/TAXONOMY/BLANK]/page/2/index.html
....
```

Fixes #96
@bep
Copy link
Member Author

bep commented Jan 26, 2015

Merged in 37445bc

@bep bep closed this Jan 26, 2015
@thomasmodeneis
Copy link

Wow thank you guys for great feature. :)
Can't wait to have it working on my blog!
Cheers

bep added a commit that referenced this pull request Jan 26, 2015
bep added a commit that referenced this pull request Jan 26, 2015
bep added a commit that referenced this pull request Jan 26, 2015
10 is a better default than 0, since no paginator pages will be created unles referenced by a `.Paginator`.

See #750
@bep bep deleted the feature/pagination branch April 18, 2017 09:19
tychoish pushed a commit to tychoish/hugo that referenced this pull request Aug 13, 2017
tychoish pushed a commit to tychoish/hugo that referenced this pull request Aug 13, 2017
tychoish pushed a commit to tychoish/hugo that referenced this pull request Aug 13, 2017
10 is a better default than 0, since no paginator pages will be created unles referenced by a `.Paginator`.

See gohugoio#750
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for pagination
4 participants