Fix html variant image prefix issue + other small fixes (#1005)

This commit is contained in:
Ben Halpern 2018-10-24 17:44:59 -04:00 committed by GitHub
parent 61ef3bdd8e
commit f124c2f65a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 4 deletions

View file

@ -106,7 +106,7 @@ module ApplicationHelper
Rails.cache.fetch(cache_key, expires_in: 1.hour) do
src = GeneratedImage.new(article).social_image
return src if src.include? "res.cloudinary"
return src if src.start_with? "https://res.cloudinary.com/"
cl_image_path(src,
type: "fetch",
width: "1000",

View file

@ -306,12 +306,12 @@ class Comment < ApplicationRecord
def before_destroy_actions
bust_cache
Comment.delay.comment_async_bust(commentable, user.username)
remove_algolia_index
reactions.destroy_all
end
def bust_cache
Comment.delay.comment_async_bust(commentable, user.username)
expire_root_fragment
cache_buster = CacheBuster.new
cache_buster.bust(commentable.path.to_s) if commentable

View file

@ -24,7 +24,7 @@ class HtmlVariant < ApplicationRecord
end
def self.find_top_for_test(tags_array)
where(group: "article_show_sidebar_cta", approved: true, published: true, target_tag: tags_array).order("success_rate DESC").limit(rand(1..10)).sample
where(group: "article_show_sidebar_cta", approved: true, published: true, target_tag: tags_array).order("success_rate DESC").limit(rand(1..15)).sample
end
def self.find_random_for_test(tags_array)
@ -45,7 +45,7 @@ class HtmlVariant < ApplicationRecord
doc.css("img").each do |img|
src = img.attr("src")
next unless src
# allow image to render as-is
next if whitelisted_image_host?(src)
img["src"] = if giphy_img?(src)
src.gsub("https://media.", "https://i.")
else
@ -65,6 +65,10 @@ class HtmlVariant < ApplicationRecord
uri.path.ends_with?(".gif")
end
def whitelisted_image_host?(src)
src.start_with?("https://res.cloudinary.com/")
end
def img_of_size(source, width = 420)
quality = if source && (source.include? ".gif")
66