mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Fixed blog broken pagination links to previous pages
This commit is contained in:
parent
bf6e66bddd
commit
c2da2d8279
@ -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)
|
||||
|
@ -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 %}
|
||||
|
@ -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)
|
||||
|
@ -87,6 +87,13 @@
|
||||
{% set class = class ~ " md-nav__item--active" %}
|
||||
{% endif %}
|
||||
|
||||
<!-- Determine active page for paginated views -->
|
||||
{% if nav_item.pages %}
|
||||
{% if page in nav_item.pages %}
|
||||
{% set nav_item = page %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
<!-- Navigation item with nested items -->
|
||||
{% if nav_item.children %}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user