Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/readthedocs/sphinx_rtd_theme.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Balder Bach <benjamin@overtag.dk>2022-10-12 21:54:10 +0300
committerGitHub <noreply@github.com>2022-10-12 21:54:10 +0300
commitc6fa4e7a40a2b7428e9b1085cd994ec24f089368 (patch)
treec70dd4c3a6b9de7e2e042ea4aa08bf0958a8f2ab
parent20607e85259f5a1885505807f932fc16cdad9449 (diff)
Move context logic for layout.html to jinja (#1356)
* Revert "Update layout.html to support a sphinx version that is not three-integers (#1345)" This reverts commit 45cf21874fb005ac86206ed26f609cb509eebbb2. * Always slice list before unpacking so number of elements is expected range `map` filter returns a generator that needs to run through the `list` filter before slicing * Let's keep it a 3-tuple but always set 3rd component to -1 -- in case a project was unpacking 3 values
-rw-r--r--docs/changelog.rst1
-rw-r--r--sphinx_rtd_theme/__init__.py9
-rw-r--r--sphinx_rtd_theme/layout.html4
3 files changed, 5 insertions, 9 deletions
diff --git a/docs/changelog.rst b/docs/changelog.rst
index 3215b4c..71d14c0 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -45,6 +45,7 @@ Minor changes
* Python 3.10 added to test matrix (#1334)
* Supplemental Docker setup for development (#1319)
* Most of setup.py migrated to setup.cfg (#1116)
+* Jinja2 context variable ``sphinx_version_info`` is now ``(major, minor, -1)``, the patch component is always ``-1``. Reason: It's complicated. (#1345)
Incompatible Changes
diff --git a/sphinx_rtd_theme/__init__.py b/sphinx_rtd_theme/__init__.py
index 9ea323f..f319098 100644
--- a/sphinx_rtd_theme/__init__.py
+++ b/sphinx_rtd_theme/__init__.py
@@ -31,12 +31,6 @@ def config_initiated(app, config):
_('The canonical_url option is deprecated, use the html_baseurl option from Sphinx instead.')
)
-
-def extend_html_context(app, pagename, templatename, context, doctree):
- # Add ``sphinx_version_info`` tuple for use in Jinja templates
- context['sphinx_version_info'] = sphinx_version
-
-
# See http://www.sphinx-doc.org/en/stable/theming.html#distribute-your-theme-as-a-python-package
def setup(app):
if python_version[0] < 3:
@@ -66,7 +60,4 @@ def setup(app):
else:
app.config.html_add_permalinks = "\uf0c1"
- # Extend the default context when rendering the templates.
- app.connect("html-page-context", extend_html_context)
-
return {'parallel_read_safe': True, 'parallel_write_safe': True}
diff --git a/sphinx_rtd_theme/layout.html b/sphinx_rtd_theme/layout.html
index 99ec01b..bb0c069 100644
--- a/sphinx_rtd_theme/layout.html
+++ b/sphinx_rtd_theme/layout.html
@@ -9,6 +9,10 @@
{%- set lang_attr = 'en' if language == None else (language | replace('_', '-')) %}
{%- set sphinx_writer = 'writer-html5' if html5_doctype else 'writer-html4' -%}
+{# Build sphinx_version_info tuple from sphinx_version string in pure Jinja #}
+{%- set (_ver_major, _ver_minor) = (sphinx_version.split('.') | list)[:2] | map('int') -%}
+{%- set sphinx_version_info = (_ver_major, _ver_minor, -1) -%}
+
<!DOCTYPE html>
<html class="{{ sphinx_writer }}" lang="{{ lang_attr }}" >
<head>