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

Change default logo alt text #1472

Merged
merged 13 commits into from
Sep 27, 2023
36 changes: 19 additions & 17 deletions docs/user_guide/branding.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,41 +77,43 @@ To reference an external website, make sure your link starts with ``http``:
}
}

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

You may set a custom ``alt text`` for your logo to replace the default ``"logo image"`` generic description.
Adding a descriptive ``alt text`` can help make your documentation more accessible to readers using screen readers or another assistive tech.
Add a logo title
----------------

To do so, customize the ``html_theme_options["logo"]["alt_text"]`` configuration option as in the following example:
To add a title in the brand section of your documentation, define a value for ``html_theme_options.logo["text"]``.
This title will appear next to the logo image if set.

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

html_theme_options = {
"logo": {
# Because the logo is also a homepage link, including "home" in the alt text is good practice
"alt_text": "My Project Name - Home",
"text": "My awesome documentation",
}
}

Add a logo title
----------------
.. note:: The ``html_title`` field will work as well if no logo images are specified.
gabalafou marked this conversation as resolved.
Show resolved Hide resolved

To add a title in the brand section of your documentation, define a value for ``html_theme_options.logo["text"]``.
This title will appear next to the logo image if set.
Customize logo alternative text
gabalafou marked this conversation as resolved.
Show resolved Hide resolved
-------------------------------

Adding a descriptive ``alt text`` can help make your documentation more accessible to readers using screen readers or other assistive tech.
gabalafou marked this conversation as resolved.
Show resolved Hide resolved

By default, the theme will set ``alt text`` to ``<Your Project Name> - Home`` unless you provide a logo title, in which case the theme sets the ``alt text`` to the empty string. The assumption is that if you provide a logo title, the title is probably doing the work of the alt text.
gabalafou marked this conversation as resolved.
Show resolved Hide resolved

However, if you don't like the default values, you may set a custom ``alt text`` for your logo.

To do so, customize the ``html_theme_options["logo"]["alt_text"]`` configuration option as in the following example:

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

html_theme_options = {
"logo": {
"text": "My awesome documentation",
# Because the logo is also a homepage link, including "home" in the alt text is good practice
"alt_text": "My Project Name - Home",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems odd to demo customization by specifying what would happen by default anyway? Here's a realistic made-up example.

Suggested change
# Because the logo is also a homepage link, including "home" in the alt text is good practice
"alt_text": "My Project Name - Home",
"logo": "path/to/pggpy/logo.jpg",
"text": "A pretty good geometry package", # something other than package name
# Because the logo is also a homepage link, including "home" in the alt text is good practice
"alt_text": "PggPy - Home",

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Hmm. This would result in assistive tech representing the link as "PggPy - Home A pretty good geometry package."

I think that this section of the docs needs to be rewritten to provide a handful of examples (maybe a couple ones marked good and a couple marked bad).

That was something I was planning to do in a follow-up PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it help if default is "Home - pkgname" instead of "pkgname - Home"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After examining logo alt text on a few sites, such as pac.bz, tink.uk, sarasoueidan.com, and w3.org, I do not think there's a clear consensus on how to do this.

So I think, ultimately, what we have is fine.

}
}

.. note:: The ``html_title`` field will work as well if no logo images are specified.


Add favicons
============

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<a class="navbar-brand logo" href="{{ href }}">
{# get all the brand information from html_theme_option #}
{% set is_logo = "light" in theme_logo["image_relative"] %}
{% set alt = theme_logo.get("alt_text", "Logo image") %}
{% set alt = theme_logo.get("alt_text", docstitle + " - Home" if not theme_logo.get("text") else "") %}
gabalafou marked this conversation as resolved.
Show resolved Hide resolved
{% if is_logo %}
{# Theme switching is only available when JavaScript is enabled.
# Thus we should add the extra image using JavaScript, defaulting
Expand Down