diff --git a/ntd2d/ntd2d_action/files/templates/ntd2d/layout.html b/ntd2d/ntd2d_action/files/templates/ntd2d/layout.html index 6091b57..713164d 100644 --- a/ntd2d/ntd2d_action/files/templates/ntd2d/layout.html +++ b/ntd2d/ntd2d_action/files/templates/ntd2d/layout.html @@ -1,4 +1,4 @@ -{{% extends "!layout.html" %}} +{{% extends "{inherited_layout}" %}} {{%- block extrahead %}} {{{{ super() }}}} diff --git a/ntd2d/ntd2d_action/sphinxdocs.py b/ntd2d/ntd2d_action/sphinxdocs.py index a965082..764336c 100644 --- a/ntd2d/ntd2d_action/sphinxdocs.py +++ b/ntd2d/ntd2d_action/sphinxdocs.py @@ -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.""" @@ -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()