Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update layout.html to support a sphinx version that is not three-integers #1345

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
pelson marked this conversation as resolved.
Show resolved Hide resolved
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
pelson marked this conversation as resolved.
Show resolved Hide resolved
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
pelson marked this conversation as resolved.
Show resolved Hide resolved


# 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 when rendering the templates.
app.connect("html-page-context", extend_html_context)
pelson marked this conversation as resolved.
Show resolved Hide resolved

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) -%}
pelson marked this conversation as resolved.
Show resolved Hide resolved

<!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") -%}
pelson marked this conversation as resolved.
Show resolved Hide resolved
<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