Update theme-color meta value to match the current page's theme
This commit is contained in:
parent
f591f5ccef
commit
ba709cdcf6
|
@ -33,7 +33,7 @@ module ThemeHelper
|
||||||
theme.attributes.each do |k, v|
|
theme.attributes.each do |k, v|
|
||||||
next unless ATTRIBUTE_MAP.key?(k)
|
next unless ATTRIBUTE_MAP.key?(k)
|
||||||
|
|
||||||
if k.include? "text"
|
if k.include? 'text'
|
||||||
hex = get_hex_color_from_theme_value(v)
|
hex = get_hex_color_from_theme_value(v)
|
||||||
body += "\t--#{ATTRIBUTE_MAP[k]}: #{get_decimal_triplet_from_hex(hex)};\n"
|
body += "\t--#{ATTRIBUTE_MAP[k]}: #{get_decimal_triplet_from_hex(hex)};\n"
|
||||||
else
|
else
|
||||||
|
@ -42,11 +42,20 @@ module ThemeHelper
|
||||||
end
|
end
|
||||||
body += "\t--turbolinks-progress-color: ##{lighten(theme.primary_color)}\n"
|
body += "\t--turbolinks-progress-color: ##{lighten(theme.primary_color)}\n"
|
||||||
|
|
||||||
body += "}"
|
body += '}'
|
||||||
|
|
||||||
content_tag(:style, body)
|
content_tag(:style, body)
|
||||||
end
|
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
|
def get_active_theme
|
||||||
if @user&.theme
|
if @user&.theme
|
||||||
if user_signed_in?
|
if user_signed_in?
|
||||||
|
@ -64,12 +73,12 @@ module ThemeHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_hex_color_from_theme_value(value)
|
def get_hex_color_from_theme_value(value)
|
||||||
('0000000' + value.to_s(16))[-6, 6]
|
("0000000#{value.to_s(16)}")[-6, 6]
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_decimal_triplet_from_hex(value)
|
def get_decimal_triplet_from_hex(value)
|
||||||
hexes = value.split(/(.{2})/).reject { |c| c.empty? }
|
hexes = value.split(/(.{2})/).reject { |c| c.empty? }
|
||||||
hexes.map(&:hex).join(", ")
|
hexes.map(&:hex).join(', ')
|
||||||
end
|
end
|
||||||
|
|
||||||
def rgb_values_from_hex(value)
|
def rgb_values_from_hex(value)
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
%meta{ charset: 'utf-8' }
|
%meta{ charset: 'utf-8' }
|
||||||
%meta{ 'http-equiv': 'X-UA-Compatible', content: 'IE=edge' }
|
%meta{ 'http-equiv': 'X-UA-Compatible', content: 'IE=edge' }
|
||||||
%meta{ name: 'viewport', content: 'width=device-width, initial-scale=1, user-scalable=no' }
|
%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: 'apple-touch-icon', href: '/apple-touch-icon-precomposed.png' }
|
||||||
%link{ rel: 'icon', href: '/images/favicon/favicon-16.png', sizes: '16x16' }
|
%link{ rel: 'icon', href: '/images/favicon/favicon-16.png', sizes: '16x16' }
|
||||||
%link{ rel: 'icon', href: '/icon-152.png', sizes: '152x152' }
|
%link{ rel: 'icon', href: '/icon-152.png', sizes: '152x152' }
|
||||||
|
|
Loading…
Reference in New Issue