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

add option to customise the alt text of the logo #893

Merged
merged 7 commits into from Aug 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions docs/conf.py
Expand Up @@ -129,6 +129,7 @@
"logo": {
"text": "PyData Theme",
"image_dark": "logo-dark.svg",
"alt_text": "PyData Theme",
},
"use_edit_page_button": True,
"show_toc_level": 1,
Expand Down
16 changes: 16 additions & 0 deletions docs/user_guide/branding.rst
Expand Up @@ -74,6 +74,22 @@ To reference an external website, make sure your link starts with ``http``:
}
}

Customize logo alternative text
-------------------------------

You may set a custom ``alt text`` to use with your logo to replace the default ("logo image").
This can make the logo more accessible to those using screen readers or other assistive tech.
To do so, use ``html_teme_options["logo"]["alt_text"]`` as in the following example:

.. code-block:: python
:caption: conf.py

html_theme_options = {
"logo": {
"alt_text": "foo",
}
}

Add a logo title
----------------

Expand Down
@@ -1,22 +1,24 @@
{% if not theme_logo.get("link") %}
{% set href = pathto(root_doc) %}
{% elif theme_logo.get("link").startswith("http") %}
{# Logo link is to external URL #}
{% set href = theme_logo.get("link") %}
{% set href = theme_logo.get("link") %} {# external url #}
{% else %}
{# Logo link is to internal page #}
{% set href = pathto(theme_logo.get("link")) %}
{% set href = pathto(theme_logo.get("link")) %} {# internal page #}
{% endif %}

<a class="navbar-brand logo" href="{{ href }}">

{# get all the brand information from html_theme_option #}
{% set is_logo = logo or theme_logo.get("image_light") or theme_logo.get("image_dark") %}
{% set image_light = theme_logo.get("image_light") or logo %}
{% set image_dark = theme_logo.get("image_dark") or logo %}
{% set image_light = image_light if image_light.startswith("http") else pathto('_static/' + image_light, 1) %}
{% set image_dark = image_dark if image_dark.startswith("http") else pathto('_static/' + image_dark, 1) %}
{% set alt = theme_logo.get("alt_text", "Logo image") %}

{% if is_logo %}
<img src="{{ image_light }}" class="logo__image only-light" alt="Logo image">
<img src="{{ image_dark }}" class="logo__image only-dark" alt="Logo image">
<img src="{{ image_light }}" class="logo__image only-light" alt="{{ alt }}">
<img src="{{ image_dark }}" class="logo__image only-dark" alt="{{ alt }}">
{% endif %}
{% if not is_logo or theme_logo.get("text") %}
<p class="title logo__title">{{ theme_logo.get("text") or docstitle }}</p>
Expand Down