diff --git a/ntd2d/ntd2d_action/files/templates/ntd2d/layout.html b/ntd2d/ntd2d_action/files/templates/ntd2d/layout.html index 7b9a64f..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 "{inherited_theme}/layout.html" %}} +{{% extends "{inherited_layout}" %}} {{%- block extrahead %}} {{{{ super() }}}} diff --git a/ntd2d/ntd2d_action/sphinxdocs.py b/ntd2d/ntd2d_action/sphinxdocs.py index a965082..e38d949 100644 --- a/ntd2d/ntd2d_action/sphinxdocs.py +++ b/ntd2d/ntd2d_action/sphinxdocs.py @@ -60,10 +60,13 @@ def epub_file(self): def pdf_file(self): return self.build_dir / "latex" / f"{self.conf.project.lower()}.pdf" + def get_theme(self, theme_name): + theme_factory = HTMLThemeFactory(self.sphinx_app) + return theme_factory.create(theme_name) + @property def stylesheet(self): - theme_factory = HTMLThemeFactory(self.sphinx_app) - theme = theme_factory.create(self.sphinx_app.config.html_theme) + theme = self.get_theme(self.sphinx_app.config.html_theme) return theme.get_config("theme", "stylesheet") @@ -149,6 +152,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.get_theme(self.inherited_theme)) + def assimilate_theme(self, name, insert_header_footer=True): """Replace configuration directory with customized html theme.""" @@ -160,6 +180,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()