Skip to content

Commit 568a5c8

Browse files
committed
Fixed blog title not being consistent in pagination
1 parent da21786 commit 568a5c8

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

material/plugins/blog/plugin.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,14 @@ def on_page_markdown(self, markdown, *, page, config, files):
202202
if page in self._resolve_views(self.blog):
203203
assert isinstance(page, View)
204204
if 0 < page.pages.index(page):
205-
return f"# {page.title}"
205+
main = page.parent
206+
207+
# We need to use the rendered title of the original view
208+
# if the author set the title in the page's contents, or
209+
# it would be overridden with the one set in mkdocs.yml,
210+
# which would result in inconsistent headings
211+
name = main._title_from_render or main.title
212+
return f"# {name}"
206213

207214
# Nothing more to be done for views
208215
return
@@ -614,9 +621,8 @@ def _generate_pages(self, view: View, config: MkDocsConfig, files: Files):
614621
file.abs_src_path = view.file.abs_src_path
615622
files.append(file)
616623

617-
# Create view and attach to parent - we don't set the title of the
618-
# view, so authors can override them in the page's content
619-
next = View(None, file, config)
624+
# Create view and attach to previous page
625+
next = View(view.title, file, config)
620626
self._attach(prev, [
621627
view.previous_page,
622628
next,

src/plugins/blog/plugin.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,14 @@ def on_page_markdown(self, markdown, *, page, config, files):
202202
if page in self._resolve_views(self.blog):
203203
assert isinstance(page, View)
204204
if 0 < page.pages.index(page):
205-
return f"# {page.title}"
205+
main = page.parent
206+
207+
# We need to use the rendered title of the original view
208+
# if the author set the title in the page's contents, or
209+
# it would be overridden with the one set in mkdocs.yml,
210+
# which would result in inconsistent headings
211+
name = main._title_from_render or main.title
212+
return f"# {name}"
206213

207214
# Nothing more to be done for views
208215
return
@@ -614,9 +621,8 @@ def _generate_pages(self, view: View, config: MkDocsConfig, files: Files):
614621
file.abs_src_path = view.file.abs_src_path
615622
files.append(file)
616623

617-
# Create view and attach to parent - we don't set the title of the
618-
# view, so authors can override them in the page's content
619-
next = View(None, file, config)
624+
# Create view and attach to previous page
625+
next = View(view.title, file, config)
620626
self._attach(prev, [
621627
view.previous_page,
622628
next,

0 commit comments

Comments
 (0)