Render social previews for tags with one of the two custom colors set (#16557)
* Initialize compare hex once in controller, fallback if color missing This PR adds a fallback color choice when there are missing bg_color_hex or text_color_hex (this is likely going to become more common as we only show the bg_color_hex in the form). The choices (black and white) may not be correct - this "custom, or default" value choice should likely be made in a decorator or on the model instead. Addresses an error reported in https://app.honeybadger.io/projects/66984/faults/83671065 * typo: Attribute name is text_color_hex
This commit is contained in:
parent
db38cebff6
commit
2fbfd68172
2 changed files with 4 additions and 3 deletions
|
|
@ -38,6 +38,7 @@ class SocialPreviewsController < ApplicationController
|
|||
|
||||
def tag
|
||||
@tag = Tag.find(params[:id])
|
||||
@compare_hex = Color::CompareHex.new([@tag.bg_color_hex || "#000000", @tag.text_color_hex || "#ffffff"])
|
||||
|
||||
set_respond
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<% accent_color = Color::CompareHex.new([@tag.bg_color_hex, @tag.text_color_hex]).biggest %>
|
||||
<% color = Color::CompareHex.new([@tag.bg_color_hex, @tag.text_color_hex]).brightness(1.4) %>
|
||||
<% dark_color = Color::CompareHex.new([@tag.bg_color_hex, @tag.text_color_hex]).brightness(0.7) %>
|
||||
<% accent_color = @compare_hex.biggest %>
|
||||
<% color = @compare_hex.brightness(1.4) %>
|
||||
<% dark_color = @compare_hex.brightness(0.7) %>
|
||||
<% not_so_rand = Random.new(@tag.id) # Using ID as seed ensures we get the same "random" numbers on each page load, Improves caching %>
|
||||
<style>
|
||||
body {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue