Full minimagick social image rollout (#19949)

* Full minimagick social image rollout

* Fix errant puts

* Remove unnecessary file
This commit is contained in:
Ben Halpern 2023-08-21 09:11:14 -04:00 committed by GitHub
parent c69d06c3ac
commit 0c92bc3f27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 10 deletions

View file

@ -5,6 +5,8 @@ module HtmlCssToImage
CACHE_EXPIRATION = 6.weeks
def self.url(html:, css: nil, google_fonts: nil)
return fallback_image if ApplicationConfig["HCTI_API_USER_ID"].blank? || ApplicationConfig["HCTI_API_KEY"].blank?
image = HTTParty.post("https://hcti.io/v1/image",
body: { html: html, css: css, google_fonts: google_fonts },
basic_auth: AUTH)

View file

@ -986,8 +986,6 @@ class Article < ApplicationRecord
end
def generate_social_image
return unless FeatureFlag.enabled?(:minimagick_social_images)
return if main_image.present?
change = saved_change_to_attribute?(:title) || saved_change_to_attribute?(:published_at)

View file

@ -134,8 +134,6 @@ class Organization < ApplicationRecord
private
def generate_social_images
return unless FeatureFlag.enabled?(:minimagick_social_images)
change = saved_change_to_attribute?(:name) || saved_change_to_attribute?(:profile_image)
return unless change && articles.published.size.positive?

View file

@ -584,8 +584,6 @@ class User < ApplicationRecord
private
def generate_social_images
return unless FeatureFlag.enabled?(:minimagick_social_images)
change = saved_change_to_attribute?(:name) || saved_change_to_attribute?(:profile_image)
return unless change && articles.published.size.positive?

View file

@ -95,17 +95,19 @@ module Images
font_size = calculate_font_size(title)
result.combine_options do |c|
escaped_title = title.gsub('"', '\\"')
c.gravity "West" # Set the origin for the text at the top left corner
c.pointsize font_size.to_s
c.draw "text 80,-39 '#{title}'" # Start drawing text 90 from the left and slightly north
c.draw "text 80,-39 \"#{escaped_title}\"" # Start drawing text 90 from the left and slightly north, with double quotes around the title
c.fill "black"
c.font BOLD_FONT_PATH.to_s
end
result.combine_options do |c|
escaped_name = author_name.gsub('"', '\\"')
c.gravity "Southwest"
c.pointsize "32"
c.draw "text 156,88 '#{author_name}'" # adjust coordinates as needed
c.draw "text 156,88 \"#{escaped_name}\"" # adjust coordinates as needed
c.fill "black"
c.font MEDIUM_FONT_PATH.to_s
end
@ -113,7 +115,7 @@ module Images
result.combine_options do |c|
c.gravity "Southwest"
c.pointsize "26"
c.draw "text 156,60 '#{date}'" # adjust coordinates as needed
c.draw "text 156,60 \"#{date}\"" # adjust coordinates as needed
c.fill "#525252"
end
end

View file

@ -0,0 +1,7 @@
module DataUpdateScripts
class RemoveMinimagickSocialFeatureFlag
def run
FeatureFlag.remove :minimagick_social_images
end
end
end

View file

@ -146,7 +146,6 @@ RSpec.configure do |config|
# "Please stub a default value first if message might be received with other args as well."
allow(FeatureFlag).to receive(:enabled?).and_call_original
allow(FeatureFlag).to receive(:enabled?).with(:connect).and_return(true)
allow(FeatureFlag).to receive(:enabled?).with(:minimagick_social_images, any_args).and_return(true)
end
config.around(:each, :flaky) do |ex|