Skip to content

Commit c2da2d8

Browse files
committed
Fixed blog broken pagination links to previous pages
1 parent bf6e66b commit c2da2d8

File tree

4 files changed

+12
-60
lines changed

4 files changed

+12
-60
lines changed

material/plugins/blog/plugin.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -339,16 +339,6 @@ def on_page_context(self, context, *, page, config, nav):
339339
if view not in self._resolve_views(self.blog):
340340
return
341341

342-
# If the current view is paginated, replace and rewire it - the current
343-
# view temporarily becomes the main view, and is reset after rendering
344-
assert isinstance(view, View)
345-
if view != page:
346-
prev = view.pages[view.pages.index(page) - 1]
347-
348-
# Replace previous page with current page
349-
items = self._resolve_siblings(view, nav)
350-
items[items.index(prev)] = page
351-
352342
# Render excerpts and prepare pagination
353343
posts, pagination = self._render(page)
354344

@@ -364,26 +354,6 @@ def pager(args: object):
364354
context["posts"] = posts
365355
context["pagination"] = pager if pagination else None
366356

367-
# After rendering a paginated view, replace the URL of the paginated view
368-
# with the URL of the original view - since we need to replace the original
369-
# view with a paginated view in `on_page_context` for correct resolution of
370-
# the active state, we must fix the paginated view URLs after rendering
371-
def on_post_page(self, output, *, page, config):
372-
if not self.config.enabled:
373-
return
374-
375-
# Skip if page is not a view managed by this instance - this plugin has
376-
# support for multiple instances, which is why this check is necessary
377-
view = self._resolve_original(page)
378-
if view not in self._resolve_views(self.blog):
379-
return
380-
381-
# If the current view is paginated, replace the URL of the paginated
382-
# view with the URL of the original view - see https://t.ly/Yeh-P
383-
assert isinstance(view, View)
384-
if view != page:
385-
page.file.url = view.file.url
386-
387357
# Remove temporary directory on shutdown
388358
def on_shutdown(self):
389359
rmtree(self.temp_dir)

material/templates/partials/nav-item.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
{% if nav_item.active %}
4040
{% set class = class ~ " md-nav__item--active" %}
4141
{% endif %}
42+
{% if nav_item.pages %}
43+
{% if page in nav_item.pages %}
44+
{% set nav_item = page %}
45+
{% endif %}
46+
{% endif %}
4247
{% if nav_item.children %}
4348
{% set indexes = [] %}
4449
{% if "navigation.indexes" in features %}

src/plugins/blog/plugin.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -339,16 +339,6 @@ def on_page_context(self, context, *, page, config, nav):
339339
if view not in self._resolve_views(self.blog):
340340
return
341341

342-
# If the current view is paginated, replace and rewire it - the current
343-
# view temporarily becomes the main view, and is reset after rendering
344-
assert isinstance(view, View)
345-
if view != page:
346-
prev = view.pages[view.pages.index(page) - 1]
347-
348-
# Replace previous page with current page
349-
items = self._resolve_siblings(view, nav)
350-
items[items.index(prev)] = page
351-
352342
# Render excerpts and prepare pagination
353343
posts, pagination = self._render(page)
354344

@@ -364,26 +354,6 @@ def pager(args: object):
364354
context["posts"] = posts
365355
context["pagination"] = pager if pagination else None
366356

367-
# After rendering a paginated view, replace the URL of the paginated view
368-
# with the URL of the original view - since we need to replace the original
369-
# view with a paginated view in `on_page_context` for correct resolution of
370-
# the active state, we must fix the paginated view URLs after rendering
371-
def on_post_page(self, output, *, page, config):
372-
if not self.config.enabled:
373-
return
374-
375-
# Skip if page is not a view managed by this instance - this plugin has
376-
# support for multiple instances, which is why this check is necessary
377-
view = self._resolve_original(page)
378-
if view not in self._resolve_views(self.blog):
379-
return
380-
381-
# If the current view is paginated, replace the URL of the paginated
382-
# view with the URL of the original view - see https://t.ly/Yeh-P
383-
assert isinstance(view, View)
384-
if view != page:
385-
page.file.url = view.file.url
386-
387357
# Remove temporary directory on shutdown
388358
def on_shutdown(self):
389359
rmtree(self.temp_dir)

src/templates/partials/nav-item.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@
8787
{% set class = class ~ " md-nav__item--active" %}
8888
{% endif %}
8989

90+
<!-- Determine active page for paginated views -->
91+
{% if nav_item.pages %}
92+
{% if page in nav_item.pages %}
93+
{% set nav_item = page %}
94+
{% endif %}
95+
{% endif %}
96+
9097
<!-- Navigation item with nested items -->
9198
{% if nav_item.children %}
9299

0 commit comments

Comments
 (0)