mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 03:10:46 -06:00
Meta topic: https://meta.discourse.org/t/meta-theme-color-is-not-respecting-current-color-scheme/239815 (#18832)
Meta topic: https://meta.discourse.org/t/meta-theme-color-is-not-respecting-current-color-scheme/239815 Currently, the dark mode theme-color `<meta>` tag doesn't apply because the light mode tag has `media="all"`. This means that the dark mode `<meta>` tag with `media="(prefers-color-scheme: dark)"` won't override it. This PR updates the light mode tag to `media="(prefers-color-scheme: light)"` if `dark_scheme_id` is defined and leaves it as `media="all"` otherwise.
This commit is contained in:
parent
d6bd4ad7ee
commit
29a32f9566
@ -626,13 +626,16 @@ module ApplicationHelper
|
||||
end
|
||||
|
||||
def discourse_theme_color_meta_tags
|
||||
result = +<<~HTML
|
||||
<meta name="theme-color" media="all" content="##{ColorScheme.hex_for_name('header_background', scheme_id)}">
|
||||
HTML
|
||||
result = +""
|
||||
if dark_scheme_id != -1
|
||||
result << <<~HTML
|
||||
<meta name="theme-color" media="(prefers-color-scheme: light)" content="##{ColorScheme.hex_for_name('header_background', scheme_id)}">
|
||||
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="##{ColorScheme.hex_for_name('header_background', dark_scheme_id)}">
|
||||
HTML
|
||||
else
|
||||
result << <<~HTML
|
||||
<meta name="theme-color" media="all" content="##{ColorScheme.hex_for_name('header_background', scheme_id)}">
|
||||
HTML
|
||||
end
|
||||
result.html_safe
|
||||
end
|
||||
|
@ -753,9 +753,9 @@ RSpec.describe ApplicationHelper do
|
||||
helper.request.cookies["dark_scheme_id"] = dark.id
|
||||
end
|
||||
|
||||
it "renders theme-color meta for the light scheme with media=all and another one for the dark scheme with media=(prefers-color-scheme: dark)" do
|
||||
it "renders theme-color meta for the light scheme with media=(prefers-color-scheme: light) and another one for the dark scheme with media=(prefers-color-scheme: dark)" do
|
||||
expect(helper.discourse_theme_color_meta_tags).to eq(<<~HTML)
|
||||
<meta name="theme-color" media="all" content="#abcdef">
|
||||
<meta name="theme-color" media="(prefers-color-scheme: light)" content="#abcdef">
|
||||
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#defabc">
|
||||
HTML
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user