Introducing a new pagination style

Hello,

I’d like to introduce a new pagination style to Hugo. I want to do the development part but I need to know how to integrate with the current code, if the contribution is likely to be integrated or not, and the guidelines I could follow for that.

basically, I am unsatisfied by the current pagination algorithm. Say you have 13 articles with pages containing 5 articles max, with A the oldest article and M the newest. I am considering the content of the following pages:

  • /articles/: the front page
  • /articles/pages/1/
  • /articles/pages/2/
  • /articles/pages/3/

They will be organized like this in Hugo :

front page: [M L K J I] (identical as page 1)
pagination: [M L K J I]   [H G F E D]   [C B A    ]
            [ page 1  ]   [ page 2  ]   [ page 3  ]

The front page is the same page as the page 1. Articles are organized from the most recent up to the oldest. Now, say I write another article N, it will shift all other articles in all pages like this:

front page: [N M L K J] (identical as page 1)
pagination: [N M L K J]   [I H G F E]   [D C B A  ]
            [ page 1  ]   [ page 2  ]   [ page 3  ]

I have another pagination scheme in mind that paginates things differently in the front page (/articles/) and on the first page (/articles/pages/1/). Articles are presented from last to first up to a limit of 5 articles on the front page. Other pages show articles from first to last, the very first article appearing on page 1. Articles from A to M would show like this:

front page: [M L K J I]
pagination: [A B C D E]   [F G H I J]   [K L M    ]
            [ page 1  ]   [ page 2  ]   [ page 3  ]

When the ne article N is added, it only changes the front page and the page 3:

front page: [N M L K J]
pagination: [A B C D E]   [F G H I J]   [K L M N  ]
            [ page 1  ]   [ page 2  ]   [ page 3  ]

One of the main benefit of this pagination model is that old pages (page 1 and 2 in the example) are left unchanged. This can be great to have permanent URLs and can also be great for caching.

@bep I see that you wrote most of the pagination code. What do you think about this?

1 Like

So if I go to your site, read the home page top to bottom, and decide I want to read more, do I click on page 1 to see the very first thing you ever posted 15 years ago? Or do I click on page 3 to see less than I just read? Or it somehow knows to take me to the middle of page 2 and tells me to scroll up? How does this work for the reader?

-j

1 Like

I think you would still like to have on every page articles from more recent to more ancient. Otherwise as @jgreely mentioned the navigation will be a complete mess for your users.

However having paging from oldest to newest sort of makes sense. So if you want it to be user-friendly, you need something like:

front page: [N M L K J]
pagination: [E D C B A]   [J I H G F]   [N M L K  ]
            [ page 1  ]   [ page 2  ]   [ page 3  ]

Then the previous articles link on your front page could lead you to to page 2 (the second highest page), where you could have a few articles repeated from the homepage (between 0 and 4 in this example), but I don’t think this is a major issue.

Did I understand your idea properly @mildred?

If you:

  1. Create the paginator with A B C D…M
  2. Pick the last paginator page to show on the front page, but reverse the order (N M L K J)
  3. If you then add N you will get what you describe… I think?

If you:

  1. Create the paginator with A B C D…M
  2. Pick the last paginator page to show on the front page, but reverse the order (N M L K J)
  3. If you then add N you will get what you describe… I think?

That would work, indeed. Are you telling me that it can be done with the current pagination code? I don’t think so, as far as I can see, the pagination code consider that the page 1 and the index page are the same pages. This needs to be dropped.


And to respond to other questions, yes, the order within pages could be reversed like you suggest @cmal. I was really thinking to have pagination with oldest articles first, but it can depend of the use case.

I have not thought too hard about it. Maybe not, as page 1 == the front page, so you cannot have two of that in any case. How would you handle that in your revised design? Add a page 0?

As to your questions about doing some code changes. The paginator implementation is considered pretty flexible and stable, so any improvements to it should be considered obvious and fairly simple – or wanted by many.

I’d add an index page separated from the other page numbers. Haven’t thought of including it as page 0 but it’s possible.

However, I am not sure how to:

  • specify pagination options: should be be configured globally on the site config?
  • paginate items on the index page in reverse order and split somewhere else than the other pages.

As to your questions about doing some code changes. The paginator implementation is considered pretty flexible and stable, so any improvements to it should be considered obvious and fairly simple – or wanted by many.

I can understand that. I’ll have to find a way t implement it simply and elegantly, and it means thinking ahead of time. I’ll have to think on how to do this.

For the moment, I can’t see a way around recomputing the pagination for the first page, and given the different kind of objects that can be paginated, this is not simple yet.