Merge pull request #178 from Retrospring/fix/theme-color

Update theme-color meta value to match the current page's theme
This commit is contained in:
Racc 2021-06-19 22:11:12 +02:00 committed by GitHub
commit 35e8e5f6c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -33,7 +33,7 @@ module ThemeHelper
theme.attributes.each do |k, v|
next unless ATTRIBUTE_MAP.key?(k)
if k.include? "text"
if k.include? 'text'
hex = get_hex_color_from_theme_value(v)
body += "\t--#{ATTRIBUTE_MAP[k]}: #{get_decimal_triplet_from_hex(hex)};\n"
else
@ -42,11 +42,20 @@ module ThemeHelper
end
body += "\t--turbolinks-progress-color: ##{lighten(theme.primary_color)}\n"
body += "}"
body += '}'
content_tag(:style, body)
end
def theme_color
theme = get_active_theme
if theme
"##{get_hex_color_from_theme_value(theme.primary_color)}"
else
'#5e35b1'
end
end
def get_active_theme
if @user&.theme
if user_signed_in?
@ -64,12 +73,12 @@ module ThemeHelper
end
def get_hex_color_from_theme_value(value)
('0000000' + value.to_s(16))[-6, 6]
("0000000#{value.to_s(16)}")[-6, 6]
end
def get_decimal_triplet_from_hex(value)
hexes = value.split(/(.{2})/).reject { |c| c.empty? }
hexes.map(&:hex).join(", ")
hexes.map(&:hex).join(', ')
end
def rgb_values_from_hex(value)

View File

@ -4,7 +4,7 @@
%meta{ charset: 'utf-8' }
%meta{ 'http-equiv': 'X-UA-Compatible', content: 'IE=edge' }
%meta{ name: 'viewport', content: 'width=device-width, initial-scale=1, user-scalable=no' }
%meta{ name: 'theme-color', content: '#5e35b1' }
%meta{ name: 'theme-color', content: theme_color }
%link{ rel: 'apple-touch-icon', href: '/apple-touch-icon-precomposed.png' }
%link{ rel: 'icon', href: '/images/favicon/favicon-16.png', sizes: '16x16' }
%link{ rel: 'icon', href: '/icon-152.png', sizes: '152x152' }