Use explicit title for titlenode, when no title is provided

Signed-off-by: Joaquin Anton <janton@nvidia.com>
This commit is contained in:
Joaquin Anton 2021-02-26 14:26:09 +01:00
parent f8878bb0b6
commit 3f62d2f294

View File

@ -39,9 +39,10 @@ class TitleCollector(EnvironmentCollector):
longtitlenode = titlenode
# explicit title set with title directive; use this only for
# the <title> tag in HTML output
if 'title' in doctree:
explicit_title = nodes.Text(doctree['title']) if 'title' in doctree else None
if explicit_title:
longtitlenode = nodes.title()
longtitlenode += nodes.Text(doctree['title'])
longtitlenode += explicit_title
# look for first section title and use that as the title
for node in doctree.traverse(nodes.section):
visitor = SphinxContentsFilter(doctree)
@ -50,7 +51,7 @@ class TitleCollector(EnvironmentCollector):
break
else:
# document has no title
titlenode += nodes.Text('<no title>')
titlenode += explicit_title or nodes.Text('<no title>')
app.env.titles[app.env.docname] = titlenode
app.env.longtitles[app.env.docname] = longtitlenode