Skip to content

Commit

Permalink
Properly handle default_mode=auto when writing logos (#1183)
Browse files Browse the repository at this point in the history
We used to only defaulting to the light version when `default_mode` was
undefined, not when it was explicitly set to `auto`. We also need to
handle the latter, as the new test shows.

Closes #1180

Co-authored-by: Jérémy Bobbio (Lunar) <lunar@softwareheritage.org>
  • Loading branch information
lunar-debian and Jérémy Bobbio (Lunar) committed Feb 15, 2023
1 parent 8d8bcb8 commit c9574e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Thus we should add the extra image using JavaScript, defaulting
# depending on the value of default_mode; and light if unset.
#}
{% if default_mode is undefined %}
{% if default_mode is undefined or default_mode == "auto" %}
{% set default_mode = "light" %}
{% endif %}
{% set js_mode = "light" if default_mode == "dark" else "dark" %}
Expand Down
15 changes: 15 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,21 @@ def test_primary_logo_is_light_when_no_default_mode(sphinx_build_factory):
assert navbar_brand.find("script", string=re.compile("only-dark")) is not None


def test_primary_logo_is_light_when_default_mode_is_set_to_auto(sphinx_build_factory):
"""Test that the primary logo image is light
(and secondary, written through JavaScript, is dark)
when default mode is explicitly set to auto."""
# Ensure no default mode is set
confoverrides = {
"html_context": {"default_mode": "auto"},
}
sphinx_build = sphinx_build_factory("base", confoverrides=confoverrides).build()
index_html = sphinx_build.html_tree("index.html")
navbar_brand = index_html.select(".navbar-brand")[0]
assert navbar_brand.find("img", class_="only-light") is not None
assert navbar_brand.find("script", string=re.compile("only-dark")) is not None


def test_primary_logo_is_light_when_default_mode_is_light(sphinx_build_factory):
"""Test that the primary logo image is light
(and secondary, written through JavaScript, is dark)
Expand Down

0 comments on commit c9574e7

Please sign in to comment.