Skip to content

Commit

Permalink
Update layout.html to support a sphinx version that is not three-inte…
Browse files Browse the repository at this point in the history
…gers. Useful for sphinx==5.2.0.post0
  • Loading branch information
pelson committed Sep 26, 2022
1 parent 70927bf commit 96ef672
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions setup.cfg
Expand Up @@ -37,7 +37,9 @@ install_requires =
sphinx >=1.6,<6
docutils <0.18
Jinja2 <3.1
packaging
tests_require =
readthedocs-sphinx-ext
pytest

[options.extras_require]
Expand Down
10 changes: 10 additions & 0 deletions sphinx_rtd_theme/__init__.py
Expand Up @@ -7,6 +7,7 @@
from os import path
from sys import version_info as python_version

import packaging.version
from sphinx import version_info as sphinx_version
from sphinx.locale import _
from sphinx.util.logging import getLogger
Expand All @@ -31,6 +32,12 @@ 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):
# Extend the page context to be albe to parse versions correctly.
context['parse_version'] = packaging.version.parse


# 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:
Expand Down Expand Up @@ -60,4 +67,7 @@ def setup(app):
else:
app.config.html_add_permalinks = "\uf0c1"

# Extend the default context for the read-the-docs theme.
app.connect("html-page-context", extend_html_context)

return {'parallel_read_safe': True, 'parallel_write_safe': True}
14 changes: 6 additions & 8 deletions sphinx_rtd_theme/layout.html
Expand Up @@ -9,9 +9,7 @@
{%- 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, _ver_bugfix) = sphinx_version.split('.') | map('int') -%}
{%- set sphinx_version_info = (_ver_major, _ver_minor, _ver_bugfix) -%}
{%- set sphinx_vn = parse_version(sphinx_version) -%}

<!DOCTYPE html>
<html class="{{ sphinx_writer }}" lang="{{ lang_attr }}" >
Expand All @@ -24,7 +22,7 @@
{%- endblock -%}

{#- CSS #}
{%- if sphinx_version_info < (4, 0) -%}
{%- if sphinx_vn < parse_version("4.0") -%}
<link rel="stylesheet" href="{{ pathto('_static/' + style, 1) }}" type="text/css" />
<link rel="stylesheet" href="{{ pathto('_static/pygments.css', 1) }}" type="text/css" />
{%- endif %}
Expand All @@ -42,7 +40,7 @@

{#- FAVICON #}
{%- if favicon %}
{%- if sphinx_version_info < (4, 0) -%}
{%- if sphinx_vn < parse_version("4.0") -%}
<link rel="shortcut icon" href="{{ pathto('_static/' + favicon, 1) }}"/>
{%- else %}
<link rel="shortcut icon" href="{{ favicon_url }}"/>
Expand All @@ -66,8 +64,8 @@
<![endif]-->
{%- if not embedded %}
{# 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 #}
{%- if sphinx_version_info >= (1, 8) -%}
{%- if sphinx_version_info < (4, 0) -%}
{%- if sphinx_vn >= parse_version("1.8") -%}
{%- if sphinx_vn < parse_version("4.0") -%}
<script id="documentation_options" data-url_root="{{ url_root }}" src="{{ pathto('_static/documentation_options.js', 1) }}"></script>
{%- endif -%}
{%- for scriptfile in script_files %}
Expand Down Expand Up @@ -143,7 +141,7 @@
{#- Not strictly valid HTML, but it's the only way to display/scale
it properly, without weird scripting or heaps of work
#}
{%- if sphinx_version_info < (4, 0) -%}
{%- if sphinx_vn < parse_version("4.0") -%}
<img src="{{ pathto('_static/' + logo, 1) }}" class="logo" alt="{{ _('Logo') }}"/>
{%- else %}
<img src="{{ logo_url }}" class="logo" alt="{{ _('Logo') }}"/>
Expand Down

0 comments on commit 96ef672

Please sign in to comment.