Skip to content

Commit 5e80b2b

Browse files
Sphinx 6: Use logo_url instead of logo (#1405)
* Sphinx 6: Use logo_url instead of logo * Handle removal of favicon template context + refactor display of logo and link so it's easier to see what belongs to <4.0 and what is >=4.0 * Adds a favicon to the demo * Import condensed version logic @agjohnson * Update sphinx_rtd_theme/layout.html Co-authored-by: Anthony <[email protected]> Co-authored-by: Anthony <[email protected]>
1 parent ce20cfc commit 5e80b2b

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

docs/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070

7171
html_logo = "demo/static/logo-wordmark-light.svg"
7272
html_show_sourcelink = True
73+
html_favicon = "demo/static/favicon.ico"
7374

7475
htmlhelp_basename = slug
7576

docs/demo/static/favicon.ico

766 Bytes
Binary file not shown.

sphinx_rtd_theme/layout.html

+16-23
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@
4040
<link rel="stylesheet" href="{{ pathto(cssfile, 1) }}" type="text/css" />
4141
{%- endfor -%}
4242

43-
{#- FAVICON #}
44-
{%- if favicon %}
45-
{%- if sphinx_version_info < (4, 0) -%}
46-
<link rel="shortcut icon" href="{{ pathto('_static/' + favicon, 1) }}"/>
47-
{%- else %}
48-
<link rel="shortcut icon" href="{{ favicon_url }}"/>
49-
{%- endif %}
50-
{%- endif -%}
43+
{#- FAVICON
44+
favicon_url is the only context var necessary since Sphinx 4.
45+
In Sphinx<4, we use favicon but need to prepend path info.
46+
#}
47+
{%- set _favicon_url = favicon_url | default(pathto('_static/' + (favicon or ""), 1)) %}
48+
{%- if favicon_url or favicon %}
49+
<link rel="shortcut icon" href="{{ _favicon_url }}"/>
50+
{%- endif %}
5151

5252
{#- CANONICAL URL (deprecated) #}
5353
{%- if theme_canonical_url and not pageurl %}
@@ -133,22 +133,15 @@
133133
<div class="wy-side-nav-search" {% if theme_style_nav_header_background %} style="background: {{theme_style_nav_header_background}}" {% endif %}>
134134
{%- block sidebartitle %}
135135

136-
{%- if logo and theme_logo_only %}
137-
<a href="{{ pathto(master_doc) }}">
138-
{%- else %}
139-
<a href="{{ pathto(master_doc) }}" class="icon icon-home"> {{ project }}
140-
{%- endif %}
141-
142-
{%- if logo %}
143-
{#- Not strictly valid HTML, but it's the only way to display/scale
144-
it properly, without weird scripting or heaps of work
145-
#}
146-
{%- if sphinx_version_info < (4, 0) -%}
147-
<img src="{{ pathto('_static/' + logo, 1) }}" class="logo" alt="{{ _('Logo') }}"/>
148-
{%- else %}
149-
<img src="{{ logo_url }}" class="logo" alt="{{ _('Logo') }}"/>
136+
{# the logo helper function was removed in Sphinx 6 and deprecated since Sphinx 4 #}
137+
{# the master_doc variable was renamed to root_doc in Sphinx 4 (master_doc still exists in later Sphinx versions) #}
138+
{%- set _logo_url = logo_url|default(pathto('_static/' + (logo or ""), 1)) %}
139+
{%- set _root_doc = root_doc|default(master_doc) %}
140+
<a href="{{ pathto(_root_doc) }}"{% if not theme_logo_only %} class="icon icon-home"{% endif %}>
141+
{% if not theme_logo_only %}{{ project }}{% endif %}
142+
{%- if logo or logo_url %}
143+
<img src="{{ _logo_url }}" class="logo" alt="{{ _('Logo') }}"/>
150144
{%- endif %}
151-
{%- endif %}
152145
</a>
153146

154147
{%- if theme_display_version %}

0 commit comments

Comments
 (0)