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:
Daniel Uber 2022-02-15 09:56:57 -06:00 committed by GitHub
parent db38cebff6
commit 2fbfd68172
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View file

@ -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

View file

@ -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 {