1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-11-12 01:50:52 +01:00

Fixed missing titles in views when blog posts have no h1 headings

This commit is contained in:
squidfunk 2023-09-03 11:00:13 +02:00
parent 3f87fe0f5b
commit 7bdd03a794
No known key found for this signature in database
GPG Key ID: 5ED40BC4F9C436DF
2 changed files with 22 additions and 4 deletions

View File

@ -143,9 +143,12 @@ class Excerpt(Page):
self.file = copy(post.file) self.file = copy(post.file)
self.post = post self.post = post
# Initialize configuration, contents and metadata # Set canonical URL, or we can't print excerpts when debugging the
# blog plugin, as the `abs_url` property would be missing
self._set_canonical_url(config.site_url)
# Initialize configuration and metadata
self.config = post.config self.config = post.config
self.markdown = post.markdown
self.meta = post.meta self.meta = post.meta
# Initialize authors and categories - note that views usually contain # Initialize authors and categories - note that views usually contain
@ -189,6 +192,12 @@ class Excerpt(Page):
processor: ExcerptTreeprocessor = self.md.treeprocessors[at] processor: ExcerptTreeprocessor = self.md.treeprocessors[at]
processor.base = page processor.base = page
# Ensure that the excerpt includes a title in its content, since the
# title is linked to the post when rendering - see https://t.ly/5Gg2F
self.markdown = self.post.markdown
if not self.post._title_from_render:
self.markdown = "\n\n".join([f"# {self.post.title}", self.markdown])
# Convert Markdown to HTML and extract excerpt # Convert Markdown to HTML and extract excerpt
self.content = self.md.convert(self.markdown) self.content = self.md.convert(self.markdown)
self.content, *_ = self.content.split(separator, 1) self.content, *_ = self.content.split(separator, 1)

View File

@ -143,9 +143,12 @@ class Excerpt(Page):
self.file = copy(post.file) self.file = copy(post.file)
self.post = post self.post = post
# Initialize configuration, contents and metadata # Set canonical URL, or we can't print excerpts when debugging the
# blog plugin, as the `abs_url` property would be missing
self._set_canonical_url(config.site_url)
# Initialize configuration and metadata
self.config = post.config self.config = post.config
self.markdown = post.markdown
self.meta = post.meta self.meta = post.meta
# Initialize authors and categories - note that views usually contain # Initialize authors and categories - note that views usually contain
@ -189,6 +192,12 @@ class Excerpt(Page):
processor: ExcerptTreeprocessor = self.md.treeprocessors[at] processor: ExcerptTreeprocessor = self.md.treeprocessors[at]
processor.base = page processor.base = page
# Ensure that the excerpt includes a title in its content, since the
# title is linked to the post when rendering - see https://t.ly/5Gg2F
self.markdown = self.post.markdown
if not self.post._title_from_render:
self.markdown = "\n\n".join([f"# {self.post.title}", self.markdown])
# Convert Markdown to HTML and extract excerpt # Convert Markdown to HTML and extract excerpt
self.content = self.md.convert(self.markdown) self.content = self.md.convert(self.markdown)
self.content, *_ = self.content.split(separator, 1) self.content, *_ = self.content.split(separator, 1)