Skip to content

Commit

Permalink
[themes]: Include project name in logo_alt by default (#12421)
Browse files Browse the repository at this point in the history
The "alt" attribute of an `<img>` is required to convey all information.
Make it clear which logo is shown.
Also make it possible for users to override the logo_alt with a custom value.
  • Loading branch information
t-8ch committed Jun 17, 2024
1 parent 581bcdd commit 6471027
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions sphinx/builders/html/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ def prepare_writing(self, docnames: set[str]) -> None:
'builder': self.name,
'parents': [],
'logo_url': logo,
'logo_alt': _('Logo of %s') % self.config.project,
'favicon_url': favicon,
'html5_doctype': True,
}
Expand Down
2 changes: 1 addition & 1 deletion sphinx/themes/agogo/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="header">
{%- if logo_url %}
<p class="logo"><a href="{{ pathto(root_doc)|e }}">
<img class="logo" src="{{ logo_url|e }}" alt="Logo"/>
<img class="logo" src="{{ logo_url|e }}" alt="{{ logo_alt|e }}"/>
</a></p>
{%- endif %}
{%- block headertitle %}
Expand Down
2 changes: 1 addition & 1 deletion sphinx/themes/basic/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h3>{{ _('Navigation') }}</h3>
{%- block sidebarlogo %}
{%- if logo_url %}
<p class="logo"><a href="{{ pathto(root_doc)|e }}">
<img class="logo" src="{{ logo_url|e }}" alt="Logo"/>
<img class="logo" src="{{ logo_url|e }}" alt="{{ logo_alt|e }}"/>
</a></p>
{%- endif %}
{%- endblock %}
Expand Down
4 changes: 2 additions & 2 deletions sphinx/themes/haiku/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
{%- block haikuheader %}
{%- if theme_full_logo != "false" %}
<a href="{{ pathto(root_doc)|e }}">
<img class="logo" src="{{ logo_url|e }}" alt="Logo"/>
<img class="logo" src="{{ logo_url|e }}" alt="{{ logo_alt|e }}"/>
</a>
{%- else %}
{%- if logo -%}
<img class="rightlogo" src="{{ logo_url|e }}" alt="Logo"/>
<img class="rightlogo" src="{{ logo_url|e }}" alt="{{ logo_alt|e }}"/>
{%- endif -%}
<h1 class="heading"><a href="{{ pathto(root_doc)|e }}">
<span>{{ shorttitle|e }}</span></a></h1>
Expand Down
2 changes: 1 addition & 1 deletion sphinx/themes/pyramid/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="header" role="banner">
<div class="logo">
<a href="{{ pathto(root_doc)|e }}">
<img class="logo" src="{{ logo_url|e }}" alt="Logo"/>
<img class="logo" src="{{ logo_url|e }}" alt="{{ logo_alt|e }}"/>
</a>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions tests/test_builders/test_build_html_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_html_remote_logo(app, status, warning):
app.build(force_all=True)

result = (app.outdir / 'index.html').read_text(encoding='utf8')
assert ('<img class="logo" src="https://www.python.org/static/img/python-logo.png" alt="Logo"/>' in result)
assert ('<img class="logo" src="https://www.python.org/static/img/python-logo.png" alt="Logo of Python"/>' in result)
assert ('<link rel="icon" href="https://www.python.org/static/favicon.ico"/>' in result)
assert not (app.outdir / 'python-logo.png').exists()

Expand All @@ -39,7 +39,7 @@ def test_html_local_logo(app, status, warning):
app.build(force_all=True)

result = (app.outdir / 'index.html').read_text(encoding='utf8')
assert ('<img class="logo" src="_static/img.png" alt="Logo"/>' in result)
assert ('<img class="logo" src="_static/img.png" alt="Logo of Python"/>' in result)
assert (app.outdir / '_static/img.png').exists()


Expand Down

0 comments on commit 6471027

Please sign in to comment.