docbrown/app/helpers/social_image_helper.rb
Regina Alyssa 8b4f7faf6b Comment Social Preview (#4260)
* Add route for comment social preview

* Add method comment to social_previews_controller

* Add view for comment social preview

* Fix spacing in meta keywords

* Update comments page keywords

* Create helper for comment social media image

* Use comment social image, add published condition for article social image

* Add tests for comment social preview

* Remove not_found fallback for social previews controller

* Remove cached_tag_list

* Update typos of word 'image' in spec
2019-10-07 10:03:03 -04:00

31 lines
938 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)
Articles::SocialImage.new(article).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