Skip to content

Commit

Permalink
Search inherited themes for inherited layout.html
Browse files Browse the repository at this point in the history
  • Loading branch information
guyer committed Mar 6, 2024
1 parent 647b2a5 commit 574a44b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ntd2d/ntd2d_action/files/templates/ntd2d/layout.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{% extends "!layout.html" %}}
{{% extends "{inherited_layout}" %}}

{{%- block extrahead %}}
{{{{ super() }}}}
Expand Down
18 changes: 18 additions & 0 deletions ntd2d/ntd2d_action/sphinxdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,23 @@ def make_conf_file(self):
def inherited_theme(self):
return self.original_docs.conf.html_theme

@property
def inherited_layout(self):
"""Find inherited layout.html
Inherited theme may not define its own :file:`layout.html`, but
rely on a theme that it, in turn, derives from.
`{% extends "!layout.html" %}` should work, but doesn't.
https://github.com/sphinx-doc/sphinx/issues/12049
"""
def get_theme_layout(theme):
if (pathlib.Path(theme.themedir) / "layout.html").exists():
return f"{theme.name}/layout.html"
else:
return get_theme_layout(theme.base)

return get_theme_layout(self.inherited_theme)

def assimilate_theme(self, name, insert_header_footer=True):
"""Replace configuration directory with customized html theme."""

Expand All @@ -160,6 +177,7 @@ def assimilate_theme(self, name, insert_header_footer=True):
self.theme = TemplateHierarchy(name=name,
destination_dir=self.conf.theme_path,
inherited_theme=self.inherited_theme,
inherited_layout=self.inherited_layout,
inherited_css=self.stylesheet,
header_footer_script=header_footer)
self.theme.write()
Expand Down

0 comments on commit 574a44b

Please sign in to comment.