[themes]: Include project name in logo_alt by default (#12421)

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.
This commit is contained in:
Thomas Weißschuh 2024-06-18 01:47:14 +02:00 committed by GitHub
parent 581bcdd140
commit 6471027d19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 8 additions and 7 deletions

View File

@ -552,6 +552,7 @@ class StandaloneHTMLBuilder(Builder):
'builder': self.name,
'parents': [],
'logo_url': logo,
'logo_alt': _('Logo of %s') % self.config.project,
'favicon_url': favicon,
'html5_doctype': True,
}

View File

@ -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 %}

View File

@ -50,7 +50,7 @@
{%- 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 %}

View File

@ -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>

View File

@ -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>

View File

@ -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()
@ -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()