Skip to content

Properly handle default_mode=auto when writing logos #1183

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

Merged
merged 1 commit into from
Feb 15, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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