Skip to content

Commit 826d59b

Browse files
committed
Control included JavaScript in templates
1 parent 6ee3168 commit 826d59b

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

pep_sphinx_extensions/__init__.py

+2-13
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,16 @@
1919
}
2020

2121

22-
# Monkeypatch StandaloneHTMLBuilder to not include JS libraries (underscore.js & jQuery)
23-
def init_less_js(self: sphinx.builders.html.StandaloneHTMLBuilder) -> None:
24-
js_files = [
25-
("js/doctools.js", {}),
26-
("language_data.js", {}),
27-
*self.app.registry.js_files,
28-
*self.get_builder_config("js_files", default="html")
29-
]
30-
for filename, attrs in js_files:
31-
self.add_js_file(filename, **attrs)
32-
33-
22+
# Monkeypatch StandaloneHTMLBuilder to whitelist child theme files only
3423
def copy_theme_static_override(self: sphinx.builders.html.StandaloneHTMLBuilder, _: dict) -> None:
24+
"""Include all files from theme/static except the templates folder."""
3525
if self.theme:
3626
source = pathlib.Path(self.theme.themedir, "static")
3727
dest = pathlib.Path(self.outdir, "_static")
3828
shutil.copytree(source, dest, dirs_exist_ok=True)
3929
shutil.rmtree(dest / "templates", ignore_errors=True)
4030

4131

42-
sphinx.builders.html.StandaloneHTMLBuilder.init_js_files = init_less_js
4332
sphinx.builders.html.StandaloneHTMLBuilder.copy_theme_static_files = copy_theme_static_override
4433
# Cache pygments formatters
4534
sphinx.highlighting.PygmentsBridge.get_formatter = functools.cache(sphinx.highlighting.PygmentsBridge.get_formatter)

pep_sphinx_extensions/theme/static/templates/layout.html

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
<link rel="stylesheet" href="{{ pathto('_static/pygments.css', 1) }}" type="text/css" />
1515
{%- endblock %}
1616

17+
{%- block scripts %}
18+
<script src="{{ pathto('_static/js/doctools.js', 1) }}"></script>
19+
{%- endblock %}
20+
1721
{%- block body_tag %}<body class="python pages pep-page">{% endblock %}
1822
{%- block header %}<header style="height: 219px; background-color: #2b5b84;"></header>{% endblock %}
1923
{%- block relbar1 %}{% endblock %}

0 commit comments

Comments
 (0)