You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support for light/dark themes has been implemented using a `data-theme`
attribute set on the `<html/>` tag. As this attribute is set using
JavaScript, this meant that it was left unset when visitors had
JavaScript disabled. This resulted in several important CSS rules not
being matched and a “broken feeling” due to wrong colors, and logo or
images shown twice.
To better support browsers with JavaScript disabled:
1. Add the same CSS rules as for the light theme when the `data-theme`
attribute is not set. This creates a safe fallback in every
situation.
2. If `default_mode` is set, write its value to the `data-theme` attribute
when writing the HTML files. This enables theme users to present
their preferred mode to visitors with JavaScript disabled.
3. Use JavaScript to add the search, theme switcher and version switcher
interface as they require JavaScript to work. This avoid unusable UI
elements to be shown to visitors with JavaScript disabled.
4. Use JavaScript to write the logo for the “other theme”, depending on
the value of `default_mode`, defaulting to “light” if unset.
5. Use JavaScript to write the announcement block to the HTML if the
announcement is a remote URL.
While this last change might seem redundant considering the other ones,
it does make the resulting pages better for search engines and text
browsers.
Closes: #1145
Copy file name to clipboardExpand all lines: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/layout.html
+7-4
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,9 @@
1
+
{# We redefine <html/> for "basic/layout.html" to add a default `data-theme` attribute when
2
+
# a default mode has been set. This also improves compatibility when JavaScript is disabled.
3
+
#}
4
+
{% set html_tag %}
5
+
<html{%ifnothtml5_doctype%}xmlns="http://www.w3.org/1999/xhtml"{%endif%}{%iflanguageisnotnone%}lang="{{ language }}"{%endif%}{%ifdefault_mode%}data-theme="{{ default_mode }}"{%endif%}>
6
+
{% endset %}
1
7
{%- extends "basic/layout.html" %}
2
8
{%- import "static/webpack-macros.html" as _webpack with context %}
3
9
{# Metadata and asset linking #}
@@ -64,10 +70,7 @@
64
70
<divclass="search-button__search-container">{% include "../components/search-field.html" %}</div>
0 commit comments