Skip to content

Commit c9574e7

Browse files
lunar-debianJérémy Bobbio (Lunar)
andauthored
Properly handle default_mode=auto when writing logos (#1183)
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) <[email protected]>
1 parent 8d8bcb8 commit c9574e7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/navbar-logo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# Thus we should add the extra image using JavaScript, defaulting
1818
# depending on the value of default_mode; and light if unset.
1919
#}
20-
{% if default_mode is undefined %}
20+
{% if default_mode is undefined or default_mode == "auto" %}
2121
{% set default_mode = "light" %}
2222
{% endif %}
2323
{% set js_mode = "light" if default_mode == "dark" else "dark" %}

tests/test_build.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,21 @@ def test_primary_logo_is_light_when_no_default_mode(sphinx_build_factory):
216216
assert navbar_brand.find("script", string=re.compile("only-dark")) is not None
217217

218218

219+
def test_primary_logo_is_light_when_default_mode_is_set_to_auto(sphinx_build_factory):
220+
"""Test that the primary logo image is light
221+
(and secondary, written through JavaScript, is dark)
222+
when default mode is explicitly set to auto."""
223+
# Ensure no default mode is set
224+
confoverrides = {
225+
"html_context": {"default_mode": "auto"},
226+
}
227+
sphinx_build = sphinx_build_factory("base", confoverrides=confoverrides).build()
228+
index_html = sphinx_build.html_tree("index.html")
229+
navbar_brand = index_html.select(".navbar-brand")[0]
230+
assert navbar_brand.find("img", class_="only-light") is not None
231+
assert navbar_brand.find("script", string=re.compile("only-dark")) is not None
232+
233+
219234
def test_primary_logo_is_light_when_default_mode_is_light(sphinx_build_factory):
220235
"""Test that the primary logo image is light
221236
(and secondary, written through JavaScript, is dark)

0 commit comments

Comments
 (0)