Skip to content

Commit 6e1c658

Browse files
committed
Fixed footer links for blog sibling pages
1 parent 502c9ca commit 6e1c658

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

material/plugins/blog/plugin.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def on_page_markdown(self, markdown, *, page, config, files):
235235
# We set the contents of the view to its title if pagination should
236236
# not keep the content of the original view on paginaged views
237237
if not self.config.pagination_keep_content:
238-
view = page.pages[0] if isinstance(page, View) else page
238+
view = self._resolve_canonical(page)
239239
if view in self._resolve_views(self.blog):
240240
assert isinstance(page, View)
241241
if page.pages.index(page):
@@ -324,7 +324,7 @@ def on_page_context(self, context, *, page, config, nav):
324324

325325
# Skip if page is not a view managed by this instance - this plugin has
326326
# support for multiple instances, which is why this check is necessary
327-
view = page.pages[0] if isinstance(page, View) else page
327+
view = self._resolve_canonical(page)
328328
if view not in self._resolve_views(self.blog):
329329
return
330330

@@ -514,6 +514,13 @@ def _resolve_views(self, view: View):
514514
assert isinstance(next, View)
515515
yield next
516516

517+
# Resolve canonical page of a page, which might be a view
518+
def _resolve_canonical(self, page: Page):
519+
if isinstance(page, View):
520+
return page.pages[0]
521+
else:
522+
return page
523+
517524
# Resolve siblings of a navigation item
518525
def _resolve_siblings(self, item: StructureItem, nav: Navigation):
519526
if isinstance(item.parent, Section):
@@ -631,6 +638,13 @@ def _attach(self, parent: StructureItem, pages: list[Page]):
631638
page.previous_page = tail
632639
page.next_page = head
633640

641+
# If the page is a view, we know that we generated it and need to
642+
# link its siblings back to the view
643+
if isinstance(page, View):
644+
view = self._resolve_canonical(page)
645+
if tail: tail.next_page = view
646+
if head: head.previous_page = view
647+
634648
# Attach a page to the given parent and link it to the previous and next
635649
# page of the given host - this is exclusively used for paginated views
636650
def _attach_at(self, parent: StructureItem, host: Page, page: Page):

src/plugins/blog/plugin.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def on_page_markdown(self, markdown, *, page, config, files):
235235
# We set the contents of the view to its title if pagination should
236236
# not keep the content of the original view on paginaged views
237237
if not self.config.pagination_keep_content:
238-
view = page.pages[0] if isinstance(page, View) else page
238+
view = self._resolve_canonical(page)
239239
if view in self._resolve_views(self.blog):
240240
assert isinstance(page, View)
241241
if page.pages.index(page):
@@ -324,7 +324,7 @@ def on_page_context(self, context, *, page, config, nav):
324324

325325
# Skip if page is not a view managed by this instance - this plugin has
326326
# support for multiple instances, which is why this check is necessary
327-
view = page.pages[0] if isinstance(page, View) else page
327+
view = self._resolve_canonical(page)
328328
if view not in self._resolve_views(self.blog):
329329
return
330330

@@ -514,6 +514,13 @@ def _resolve_views(self, view: View):
514514
assert isinstance(next, View)
515515
yield next
516516

517+
# Resolve canonical page of a page, which might be a view
518+
def _resolve_canonical(self, page: Page):
519+
if isinstance(page, View):
520+
return page.pages[0]
521+
else:
522+
return page
523+
517524
# Resolve siblings of a navigation item
518525
def _resolve_siblings(self, item: StructureItem, nav: Navigation):
519526
if isinstance(item.parent, Section):
@@ -631,6 +638,13 @@ def _attach(self, parent: StructureItem, pages: list[Page]):
631638
page.previous_page = tail
632639
page.next_page = head
633640

641+
# If the page is a view, we know that we generated it and need to
642+
# link its siblings back to the view
643+
if isinstance(page, View):
644+
view = self._resolve_canonical(page)
645+
if tail: tail.next_page = view
646+
if head: head.previous_page = view
647+
634648
# Attach a page to the given parent and link it to the previous and next
635649
# page of the given host - this is exclusively used for paginated views
636650
def _attach_at(self, parent: StructureItem, host: Page, page: Page):

0 commit comments

Comments
 (0)