From 0c92bc3f27050279f9127a48cc9ad60834316763 Mon Sep 17 00:00:00 2001 From: Ben Halpern Date: Mon, 21 Aug 2023 09:11:14 -0400 Subject: [PATCH] Full minimagick social image rollout (#19949) * Full minimagick social image rollout * Fix errant puts * Remove unnecessary file --- app/lib/html_css_to_image.rb | 2 ++ app/models/article.rb | 2 -- app/models/organization.rb | 2 -- app/models/user.rb | 2 -- app/services/images/generate_social_image_magickally.rb | 8 +++++--- ...0230817161811_remove_minimagick_social_feature_flag.rb | 7 +++++++ spec/rails_helper.rb | 1 - 7 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 lib/data_update_scripts/20230817161811_remove_minimagick_social_feature_flag.rb diff --git a/app/lib/html_css_to_image.rb b/app/lib/html_css_to_image.rb index d570889c5..1132b62fa 100644 --- a/app/lib/html_css_to_image.rb +++ b/app/lib/html_css_to_image.rb @@ -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) diff --git a/app/models/article.rb b/app/models/article.rb index 373b8a2a8..16f343969 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -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) diff --git a/app/models/organization.rb b/app/models/organization.rb index f98b5cfaf..da06a4e5f 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -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? diff --git a/app/models/user.rb b/app/models/user.rb index c0ca6d439..ef90c61bc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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? diff --git a/app/services/images/generate_social_image_magickally.rb b/app/services/images/generate_social_image_magickally.rb index 8affe871f..ab1f9ad9f 100644 --- a/app/services/images/generate_social_image_magickally.rb +++ b/app/services/images/generate_social_image_magickally.rb @@ -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 diff --git a/lib/data_update_scripts/20230817161811_remove_minimagick_social_feature_flag.rb b/lib/data_update_scripts/20230817161811_remove_minimagick_social_feature_flag.rb new file mode 100644 index 000000000..290e463ee --- /dev/null +++ b/lib/data_update_scripts/20230817161811_remove_minimagick_social_feature_flag.rb @@ -0,0 +1,7 @@ +module DataUpdateScripts + class RemoveMinimagickSocialFeatureFlag + def run + FeatureFlag.remove :minimagick_social_images + end + end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 5250a8b04..40360bc5f 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -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|