docbrown/app/view_objects/cloud_cover_url.rb
Ben Halpern eb768a24ad
[deploy] Add explicit robots instruction meta tag and adjust cloudinary (#9601)
* Add explicit robots instruction meta tag and adjust cloudinary

* Fix tests

* Fix test to account for random input

* Skip test
2020-08-02 11:25:46 -04:00

38 lines
884 B
Ruby

class CloudCoverUrl
include CloudinaryHelper
include ActionView::Helpers::AssetUrlHelper
def initialize(url)
@url = url
end
def call
return if url.blank?
return url if Rails.env.development?
width = 1000
height = 420
quality = "auto"
cl_image_path(url_without_prefix_nesting(url, width),
type: "fetch",
width: width,
height: height,
crop: "imagga_scale",
quality: quality,
flags: "progressive",
fetch_format: "auto",
sign_url: true)
end
private
def url_without_prefix_nesting(url, width)
return url if url.blank?
return url unless url.start_with?("https://res.cloudinary.com/") && url.include?("w_#{width}/https://")
url.split("w_#{width}/").last
end
attr_reader :url
end