Skip to content

Commit e6bd3f0

Browse files
committed
Don't use extension to add sphinx_version_info tuple to build context
1 parent ee32a53 commit e6bd3f0

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

sphinx_rtd_theme/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ def config_initiated(app, config):
3131
_('The canonical_url option is deprecated, use the html_baseurl option from Sphinx instead.')
3232
)
3333

34-
def page_context_handler(app, pagename, templatename, context, doctree):
35-
"""Expose sphinx version to html templates in a more programatic way."""
36-
context['sphinx_version_tuple'] = sphinx_version
37-
3834
# See http://www.sphinx-doc.org/en/stable/theming.html#distribute-your-theme-as-a-python-package
3935
def setup(app):
4036
if python_version[0] < 3:
@@ -64,6 +60,4 @@ def setup(app):
6460
else:
6561
app.config.html_add_permalinks = "\uf0c1"
6662

67-
app.connect('html-page-context', page_context_handler)
68-
6963
return {'parallel_read_safe': True, 'parallel_write_safe': True}

sphinx_rtd_theme/layout.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
{%- set lang_attr = 'en' if language == None else (language | replace('_', '-')) %}
1010
{%- set sphinx_writer = 'writer-html5' if html5_doctype else 'writer-html4' -%}
1111

12+
{# Build sphinx_version_info tuple from sphinx_version string in pure Jinja #}
13+
{%- set (_ver_major, _ver_minor, _ver_bugfix) = sphinx_version.split('.') | map('int') -%}
14+
{%- set sphinx_version_info = (_ver_major, _ver_minor, _ver_bugfix) -%}
15+
1216
<!DOCTYPE html>
1317
<html class="{{ sphinx_writer }}" lang="{{ lang_attr }}" >
1418
<head>
@@ -20,7 +24,7 @@
2024
{%- endblock -%}
2125

2226
{#- CSS #}
23-
{%- if sphinx_version_tuple < (4, 0,) -%}
27+
{%- if sphinx_version_info < (4, 0) -%}
2428
<link rel="stylesheet" href="{{ pathto('_static/' + style, 1) }}" type="text/css" />
2529
<link rel="stylesheet" href="{{ pathto('_static/pygments.css', 1) }}" type="text/css" />
2630
{%- endif %}
@@ -58,8 +62,8 @@
5862
<![endif]-->
5963
{%- if not embedded %}
6064
{# XXX Sphinx 1.8.0 made this an external js-file, quick fix until we refactor the template to inherert more blocks directly from sphinx #}
61-
{%- if sphinx_version_tuple >= (1, 8) -%}
62-
{%- if sphinx_version_tuple < (4, 0) -%}
65+
{%- if sphinx_version_info >= (1, 8) -%}
66+
{%- if sphinx_version_info < (4, 0) -%}
6367
<script id="documentation_options" data-url_root="{{ url_root }}" src="{{ pathto('_static/documentation_options.js', 1) }}"></script>
6468
{%- endif -%}
6569
{%- for scriptfile in script_files %}

0 commit comments

Comments
 (0)