Update theme_color_tags helper for new theme infrastructure (#37519)

This commit is contained in:
Claire 2026-01-16 11:00:04 +01:00 committed by GitHub
parent be00db4fa3
commit e58084a85f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 18 deletions

View File

@ -28,14 +28,17 @@ module ThemeHelper
end
end
def theme_color_tags(theme)
if theme == 'system'
def theme_color_tags(color_scheme)
case color_scheme
when 'auto'
''.html_safe.tap do |tags|
tags << tag.meta(name: 'theme-color', content: Themes::THEME_COLORS[:dark], media: '(prefers-color-scheme: dark)')
tags << tag.meta(name: 'theme-color', content: Themes::THEME_COLORS[:light], media: '(prefers-color-scheme: light)')
end
else
tag.meta name: 'theme-color', content: theme_color_for(theme)
when 'light'
tag.meta name: 'theme-color', content: Themes::THEME_COLORS[:light]
when 'dark'
tag.meta name: 'theme-color', content: Themes::THEME_COLORS[:dark]
end
end
@ -65,8 +68,4 @@ module ThemeHelper
Setting.custom_css&.then { |content| Digest::SHA256.hexdigest(content) }
end
end
def theme_color_for(theme)
theme == 'mastodon-light' ? Themes::THEME_COLORS[:light] : Themes::THEME_COLORS[:dark]
end
end

View File

@ -21,7 +21,7 @@
%link{ rel: 'mask-icon', href: frontend_asset_path('images/logo-symbol-icon.svg'), color: '#6364FF' }/
%link{ rel: 'manifest', href: manifest_path(format: :json) }/
= javascript_inline_tag 'theme-selection.js'
= theme_color_tags current_theme
= theme_color_tags color_scheme
%meta{ name: 'mobile-web-app-capable', content: 'yes' }/
%title= html_title

View File

@ -49,12 +49,12 @@ RSpec.describe ThemeHelper do
end
describe 'theme_color_tags' do
let(:result) { helper.theme_color_tags(theme) }
let(:result) { helper.theme_color_tags(color_scheme) }
context 'when using system theme' do
let(:theme) { 'system' }
let(:color_scheme) { 'auto' }
it 'returns the mastodon-light and default stylesheets with correct color schemes' do
it 'returns both color schemes with appropriate media queries' do
expect(html_theme_colors.first.attributes.symbolize_keys)
.to include(
content: have_attributes(value: Themes::THEME_COLORS[:dark]),
@ -68,10 +68,10 @@ RSpec.describe ThemeHelper do
end
end
context 'when using mastodon-light theme' do
let(:theme) { 'mastodon-light' }
context 'when light color scheme' do
let(:color_scheme) { 'light' }
it 'returns the theme stylesheet without color scheme information' do
it 'returns the light color' do
expect(html_theme_colors.first.attributes.symbolize_keys)
.to include(
content: have_attributes(value: Themes::THEME_COLORS[:light])
@ -79,10 +79,10 @@ RSpec.describe ThemeHelper do
end
end
context 'when using other theme' do
let(:theme) { 'contrast' }
context 'when using dark color scheme' do
let(:color_scheme) { 'dark' }
it 'returns the theme stylesheet without color scheme information' do
it 'returns the dark color' do
expect(html_theme_colors.first.attributes.symbolize_keys)
.to include(
content: have_attributes(value: Themes::THEME_COLORS[:dark])