From c2da2d82792abc7cc056091fbf9c5c196a5d5b17 Mon Sep 17 00:00:00 2001 From: squidfunk Date: Sun, 26 Nov 2023 12:46:32 +0100 Subject: [PATCH] Fixed blog broken pagination links to previous pages --- material/plugins/blog/plugin.py | 30 ----------------------- material/templates/partials/nav-item.html | 5 ++++ src/plugins/blog/plugin.py | 30 ----------------------- src/templates/partials/nav-item.html | 7 ++++++ 4 files changed, 12 insertions(+), 60 deletions(-) diff --git a/material/plugins/blog/plugin.py b/material/plugins/blog/plugin.py index ab0605b2a..90eb2274a 100644 --- a/material/plugins/blog/plugin.py +++ b/material/plugins/blog/plugin.py @@ -339,16 +339,6 @@ class BlogPlugin(BasePlugin[BlogConfig]): if view not in self._resolve_views(self.blog): return - # If the current view is paginated, replace and rewire it - the current - # view temporarily becomes the main view, and is reset after rendering - assert isinstance(view, View) - if view != page: - prev = view.pages[view.pages.index(page) - 1] - - # Replace previous page with current page - items = self._resolve_siblings(view, nav) - items[items.index(prev)] = page - # Render excerpts and prepare pagination posts, pagination = self._render(page) @@ -364,26 +354,6 @@ class BlogPlugin(BasePlugin[BlogConfig]): context["posts"] = posts context["pagination"] = pager if pagination else None - # After rendering a paginated view, replace the URL of the paginated view - # with the URL of the original view - since we need to replace the original - # view with a paginated view in `on_page_context` for correct resolution of - # the active state, we must fix the paginated view URLs after rendering - def on_post_page(self, output, *, page, config): - if not self.config.enabled: - return - - # Skip if page is not a view managed by this instance - this plugin has - # support for multiple instances, which is why this check is necessary - view = self._resolve_original(page) - if view not in self._resolve_views(self.blog): - return - - # If the current view is paginated, replace the URL of the paginated - # view with the URL of the original view - see https://t.ly/Yeh-P - assert isinstance(view, View) - if view != page: - page.file.url = view.file.url - # Remove temporary directory on shutdown def on_shutdown(self): rmtree(self.temp_dir) diff --git a/material/templates/partials/nav-item.html b/material/templates/partials/nav-item.html index 5e8807928..d127bb16c 100644 --- a/material/templates/partials/nav-item.html +++ b/material/templates/partials/nav-item.html @@ -39,6 +39,11 @@ {% if nav_item.active %} {% set class = class ~ " md-nav__item--active" %} {% endif %} + {% if nav_item.pages %} + {% if page in nav_item.pages %} + {% set nav_item = page %} + {% endif %} + {% endif %} {% if nav_item.children %} {% set indexes = [] %} {% if "navigation.indexes" in features %} diff --git a/src/plugins/blog/plugin.py b/src/plugins/blog/plugin.py index ab0605b2a..90eb2274a 100644 --- a/src/plugins/blog/plugin.py +++ b/src/plugins/blog/plugin.py @@ -339,16 +339,6 @@ class BlogPlugin(BasePlugin[BlogConfig]): if view not in self._resolve_views(self.blog): return - # If the current view is paginated, replace and rewire it - the current - # view temporarily becomes the main view, and is reset after rendering - assert isinstance(view, View) - if view != page: - prev = view.pages[view.pages.index(page) - 1] - - # Replace previous page with current page - items = self._resolve_siblings(view, nav) - items[items.index(prev)] = page - # Render excerpts and prepare pagination posts, pagination = self._render(page) @@ -364,26 +354,6 @@ class BlogPlugin(BasePlugin[BlogConfig]): context["posts"] = posts context["pagination"] = pager if pagination else None - # After rendering a paginated view, replace the URL of the paginated view - # with the URL of the original view - since we need to replace the original - # view with a paginated view in `on_page_context` for correct resolution of - # the active state, we must fix the paginated view URLs after rendering - def on_post_page(self, output, *, page, config): - if not self.config.enabled: - return - - # Skip if page is not a view managed by this instance - this plugin has - # support for multiple instances, which is why this check is necessary - view = self._resolve_original(page) - if view not in self._resolve_views(self.blog): - return - - # If the current view is paginated, replace the URL of the paginated - # view with the URL of the original view - see https://t.ly/Yeh-P - assert isinstance(view, View) - if view != page: - page.file.url = view.file.url - # Remove temporary directory on shutdown def on_shutdown(self): rmtree(self.temp_dir) diff --git a/src/templates/partials/nav-item.html b/src/templates/partials/nav-item.html index 24d74a1a4..27c53c9d6 100644 --- a/src/templates/partials/nav-item.html +++ b/src/templates/partials/nav-item.html @@ -87,6 +87,13 @@ {% set class = class ~ " md-nav__item--active" %} {% endif %} + + {% if nav_item.pages %} + {% if page in nav_item.pages %} + {% set nav_item = page %} + {% endif %} + {% endif %} + {% if nav_item.children %}