Skip to content

Commit 45cf218

Browse files
pelsonAA-Turnerbenjaoming
authored
Update layout.html to support a sphinx version that is not three-integers (#1345)
* Update layout.html to support a sphinx version that is not three-integers. Useful for sphinx==5.2.0.post0 * Apply suggestions from code review Co-authored-by: Adam Turner <[email protected]> * No reason to only have the first three elements from the sphinx version Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Benjamin Balder Bach <[email protected]>
1 parent 855e89b commit 45cf218

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

sphinx_rtd_theme/__init__.py

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

34+
35+
def extend_html_context(app, pagename, templatename, context, doctree):
36+
# Add ``sphinx_version_info`` tuple for use in Jinja templates
37+
context['sphinx_version_info'] = sphinx_version
38+
39+
3440
# See http://www.sphinx-doc.org/en/stable/theming.html#distribute-your-theme-as-a-python-package
3541
def setup(app):
3642
if python_version[0] < 3:
@@ -60,4 +66,7 @@ def setup(app):
6066
else:
6167
app.config.html_add_permalinks = "\uf0c1"
6268

69+
# Extend the default context when rendering the templates.
70+
app.connect("html-page-context", extend_html_context)
71+
6372
return {'parallel_read_safe': True, 'parallel_write_safe': True}

sphinx_rtd_theme/layout.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
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-
1612
<!DOCTYPE html>
1713
<html class="{{ sphinx_writer }}" lang="{{ lang_attr }}" >
1814
<head>

0 commit comments

Comments
 (0)