Skip to content

Commit

Permalink
Preserve legacy behavior only for edge cases in plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed Apr 23, 2023
1 parent 85d0eea commit cc4e4c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion mkdocs/structure/pages.py
Expand Up @@ -17,7 +17,7 @@

from mkdocs.structure.files import File, Files
from mkdocs.structure.toc import get_toc
from mkdocs.utils import get_build_date, meta, weak_property
from mkdocs.utils import get_build_date, get_markdown_title, meta, weak_property

if TYPE_CHECKING:
from mkdocs.config.defaults import MkDocsConfig
Expand Down Expand Up @@ -259,6 +259,10 @@ def title(self) -> Optional[str]:

if self._title_from_render:
return self._title_from_render
elif self.content is None: # Preserve legacy behavior only for edge cases in plugins.
title_from_md = get_markdown_title(self.markdown)
if title_from_md is not None:
return title_from_md

if self.is_homepage:
return 'Home'
Expand Down
2 changes: 1 addition & 1 deletion mkdocs/tests/structure/page_tests.py
Expand Up @@ -299,7 +299,7 @@ def test_page_title_from_markdown(self):
self.assertEqual(pg.next_page, None)
self.assertEqual(pg.parent, None)
self.assertEqual(pg.previous_page, None)
self.assertEqual(pg.title, 'Testing')
self.assertEqual(pg.title, 'Welcome to MkDocs')
pg.render(cfg, fl)
self.assertEqual(pg.title, 'Welcome to MkDocs')

Expand Down

0 comments on commit cc4e4c2

Please sign in to comment.