Skip to content

Commit

Permalink
Sphinx 6: Use logo_url instead of logo (readthedocs#1405)
Browse files Browse the repository at this point in the history
* 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 <aj@ohess.org>

Co-authored-by: Anthony <aj@ohess.org>
  • Loading branch information
benjaoming and agjohnson committed Jan 17, 2023
1 parent ce20cfc commit 5e80b2b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@

html_logo = "demo/static/logo-wordmark-light.svg"
html_show_sourcelink = True
html_favicon = "demo/static/favicon.ico"

htmlhelp_basename = slug

Expand Down
Binary file added docs/demo/static/favicon.ico
Binary file not shown.
39 changes: 16 additions & 23 deletions sphinx_rtd_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
<link rel="stylesheet" href="{{ pathto(cssfile, 1) }}" type="text/css" />
{%- endfor -%}

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

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

{%- if logo and theme_logo_only %}
<a href="{{ pathto(master_doc) }}">
{%- else %}
<a href="{{ pathto(master_doc) }}" class="icon icon-home"> {{ project }}
{%- endif %}

{%- if logo %}
{#- 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) -%}
<img src="{{ pathto('_static/' + logo, 1) }}" class="logo" alt="{{ _('Logo') }}"/>
{%- else %}
<img src="{{ logo_url }}" class="logo" alt="{{ _('Logo') }}"/>
{# the logo helper function was removed in Sphinx 6 and deprecated since Sphinx 4 #}
{# the master_doc variable was renamed to root_doc in Sphinx 4 (master_doc still exists in later Sphinx versions) #}
{%- set _logo_url = logo_url|default(pathto('_static/' + (logo or ""), 1)) %}
{%- set _root_doc = root_doc|default(master_doc) %}
<a href="{{ pathto(_root_doc) }}"{% if not theme_logo_only %} class="icon icon-home"{% endif %}>
{% if not theme_logo_only %}{{ project }}{% endif %}
{%- if logo or logo_url %}
<img src="{{ _logo_url }}" class="logo" alt="{{ _('Logo') }}"/>
{%- endif %}
{%- endif %}
</a>

{%- if theme_display_version %}
Expand Down

0 comments on commit 5e80b2b

Please sign in to comment.