docbrown/app/helpers/social_image_helper.rb
Julianna Tetreault 91e4cd26ed
Specify SEO-Optimized Width and Height for Cover Images (#7447)
* Specify SEO optimized width and height for cover images in articles JSON-LD
  * Specify 1:1 ratio for cover images in stories_controller.rb
  * Specify 4:3 ratio for cover images in stories_controller.rb
  * Specify 16:9 ratio for cover images in stories_controller.rb
  * Optimize images for SEO purposes by specifying width and height

* Change aspect ratio to be 1600x900 in stories_controller.rb
  * Makes aspect ratio for article cover images smaller in JSON-LD

* Add options to social_image_helper.rb
  * Adds options to article_social_image_url call
2020-04-23 08:30:28 -06:00

31 lines
958 B
Ruby

module SocialImageHelper
# After this date we use SocialPreview controller directly rather than passing to URL2PNG.
# Keeping old URLs around since they are already generated.
SOCIAL_PREVIEW_MIGRATION_DATETIME = Time.zone.parse("2019-04-22T00:00:00Z")
def user_social_image_url(user)
return GeneratedImage.new(user).social_image unless use_new_social_url?(user)
if user.is_a?(Organization)
organization_social_preview_url(user, format: :png)
else
user_social_preview_url(user, format: :png)
end
end
def listing_social_image_url(listing)
listing_social_preview_url(listing, format: :png)
end
def article_social_image_url(article, **options)
Articles::SocialImage.new(article, options).url
end
def comment_social_image_url(comment)
comment_social_preview_url(comment, format: :png)
end
def use_new_social_url?(resource)
resource.updated_at > SOCIAL_PREVIEW_MIGRATION_DATETIME
end
end