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

Links to previous pages are wrongly generated in latest blog posts pagination #6365

Closed
4 tasks done
vedranmiletic opened this issue Nov 19, 2023 · 3 comments
Closed
4 tasks done
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@vedranmiletic
Copy link
Contributor

Context

No response

Bug description

When there is three or more pages of latest posts on the blog, some of the pagination links at the bottom of the page are wrongly generated from page 3 onward.

Related links

Reproduction

9.4.10-latest-posts-pagination-links.zip

Steps to reproduce

  1. mkdocs serve in the minimal example
  2. Navigate to /blog/, go to the bottom of the page, observe by hovering and looking in the browser status bar or using developer tools that the links to pages 2, 3, and 4 are correct
  3. Navigate to /blog/page/2/, observe that the links to pages 1, 3, and 4 are correct
  4. Navigate to /blog/page/3/, observe that the links to pages 1 and 4 are correct, while the link to page 2 is actually the link to page 1
  5. Navigate to /blog/page/3/, observe that the links to page 1 is correct, while the links to page 2 and 3 are actually the links to page 1 as well

Browser

No response

Before submitting

@squidfunk
Copy link
Owner

Thanks for reporting. It's definitely related to the changed we introduced to fix #5952. Reverting that change fixes it I will check and see how we can make both things work.

@squidfunk
Copy link
Owner

Fixed in c2da2d8. Okay, so this took longer than expected, but I think I finally have a better solution for this.

The blog plugin implements pagination as a special type of page, which can contain paginated views of themselves. When those pages are rendered in the navigation, the currently active page should appear as the same navigation item as the first page. To support this, I had to jump through some hoops, namely replacing the top-level page when rendering a paginated view. This led to many problems and workarounds, all of which we tried to fix in the past, but there where always new edge cases that made this tricky to get right.

This commit takes another approach: it leaves the navigation structure as it is, and implements pagination in template land. Turns out, you only need 5 lines of Jinja to support this and make the entire logic much simpler and less fragile. The only thing we need to implement is to replace links from a paginated view to itself with a link to the first page. If we wouldn't do that, clicking on the navigation item when paginating would lead you to the same page, but IMHO the expected outcome is navigation to the first page. I've also tested previously reported issues, including #5952, and it seems that this new approach seems to not break anything we fixed in the past. Best thing: we replaced 30 lines with 5.

Please check if this fixes your problem.

@squidfunk squidfunk added the resolved Issue is resolved, yet unreleased if open label Nov 26, 2023
@squidfunk
Copy link
Owner

Released as part of 9.4.13.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

2 participants