Remove generated social images, except for articles#show (#18118)

* Prefer main_social_image (except on articles#show)

See https://github.com/forem/forem-internal-eng/issues/485

* Cleanup social media helpers no longer in use
This commit is contained in:
Joshua Wehner 2022-07-18 12:29:21 +02:00 committed by GitHub
parent 54f3d704fe
commit 4e17649e15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 17 additions and 73 deletions

View file

@ -1,31 +1,5 @@
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 Images::GenerateSocialImage.call(user) 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

View file

@ -25,8 +25,8 @@
<meta property="og:url" content="<%= app_url(@root_comment.path) %>" />
<meta property="og:title" content="<%= t("views.comments.meta.og.title_rel", root: truncate(strip_tags(@root_comment.processed_html), length: 50), site: community_name) %>" />
<meta name="twitter:title" content="<%= t("views.comments.meta.og.title_rel", root: truncate(strip_tags(@root_comment.processed_html), length: 50), site: community_name) %>">
<meta property="og:image" content="<%= comment_social_image_url(@root_comment) %>" />
<meta name="twitter:image" content="<%= comment_social_image_url(@root_comment) %>">
<meta property="og:image" content="<%= Settings::General.main_social_image %>">
<meta name="twitter:image:src" content="<%= Settings::General.main_social_image %>">
<% if @root_comment.score < 0 || @commentable.score < 0 %>
<meta name="googlebot" content="noindex">
<meta name="googlebot" content="nofollow">
@ -37,8 +37,8 @@
<meta property="og:title" content="<%= t("views.comments.meta.og.title_root", title: @commentable.title, site: community_name) %>" />
<meta name="twitter:title" content="<%= t("views.comments.meta.og.title_root", title: @commentable.title, site: community_name) %>">
<% if @commentable.class.name == "Article" && @commentable.published %>
<meta property="og:image" content="<%= article_social_image_url(@commentable) %>" />
<meta name="twitter:image" content="<%= article_social_image_url(@commentable) %>">
<meta property="og:image" content="<%= Settings::General.main_social_image %>">
<meta name="twitter:image:src" content="<%= Settings::General.main_social_image %>">
<% end %>
<% end %>
<% end %>

View file

@ -11,10 +11,10 @@
<% if @displayed_listing %>
<meta property="og:title" content="<%= truncate @displayed_listing.title, length: 54 %>">
<meta property="og:description" content="<%= t("views.listings.meta.description", community: community_name) %>" />
<meta property="og:image" content="<%= listing_social_image_url @displayed_listing %>">
<meta property="og:image" content="<%= Settings::General.main_social_image %>">
<meta name="twitter:title" content="<%= truncate @displayed_listing.title, length: 54 %>">
<meta name="twitter:description" content="<%= t("views.listings.meta.description", community: community_name) %>">
<meta name="twitter:image:src" content="<%= listing_social_image_url @displayed_listing %>">
<meta name="twitter:image:src" content="<%= Settings::General.main_social_image %>">
<% else %>
<meta property="og:title" content="Listings" />
<meta property="og:description" content="<%= Settings::Community.community_description %>" />

View file

@ -7,7 +7,7 @@
<meta property="og:type" content="article" />
<meta property="og:url" content="<%= app_url(@page.path) %>" />
<meta property="og:title" content="<%= @page.title %> — <%= community_name %>" />
<meta property="og:image" content="<%= @page.social_image_url || Settings::General.main_social_image %>" />
<meta property="og:image" content="<%= Settings::General.main_social_image %>">
<meta property="og:description" content="<%= @page.description %>" />
<meta property="og:site_name" content="<%= community_name %>" />
@ -15,7 +15,7 @@
<meta name="twitter:site" content="@<%= Settings::General.social_media_handles["twitter"] %>">
<meta name="twitter:title" content="<%= @page.title %> — <%= community_name %>">
<meta name="twitter:description" content="<%= @page.description %>">
<meta name="twitter:image:src" content="<%= @page.social_image_url || Settings::General.main_social_image %>">
<meta name="twitter:image:src" content="<%= Settings::General.main_social_image %>">
<% end %>
<main id="main-content">

View file

@ -18,12 +18,12 @@
<% if @episode.social_image.present? %>
<meta name="twitter:card" content="summary_large_image">
<meta property="og:image" content="<%= @episode.social_image_url %>">
<meta name="twitter:image:src" content="<%= @episode.social_image_url %>">
<meta property="og:image" content="<%= Settings::General.main_social_image %>">
<meta name="twitter:image:src" content="<%= Settings::General.main_social_image %>">
<% else %>
<meta name="twitter:card" content="summary">
<meta property="og:image" content="<%= @episode.image_url || @podcast.image_url %>">
<meta name="twitter:image:src" content="<%= @episode.image_url || @podcast.image_url %>">
<meta property="og:image" content="<%= Settings::General.main_social_image %>">
<meta name="twitter:image:src" content="<%= Settings::General.main_social_image %>">
<% end %>
<% end %>

View file

@ -22,8 +22,8 @@
<% if @tag %>
<meta name="twitter:card" content="summary_large_image">
<meta property="og:image" content="<%= tag_social_preview_url(@tag, format: :png) %>">
<meta name="twitter:image:src" content="<%= tag_social_preview_url(@tag, format: :png) %>">
<meta property="og:image" content="<%= Settings::General.main_social_image %>">
<meta name="twitter:image:src" content="<%= Settings::General.main_social_image %>">
<% else %>
<meta property="og:image" content="<%= Settings::General.main_social_image %>">
<meta name="twitter:image:src" content="<%= Settings::General.main_social_image %>">

View file

@ -5,7 +5,7 @@
<meta property="og:type" content="website" />
<meta property="og:url" content="<%= user_url(@user) %>" />
<meta property="og:title" content="<%= t("views.users.meta.og.title", user: @user.name, community: community_name) %>" />
<meta property="og:image" content="<%= user_social_image_url(@user) %>">
<meta property="og:image" content="<%= Settings::General.main_social_image %>" />
<meta property="og:description" content="<%= @user.tag_line %>" />
<meta property="og:site_name" content="<%= community_name %>" />
<meta name="twitter:card" content="summary_large_image">
@ -13,7 +13,7 @@
<meta name="twitter:creator" content="@<%= @user.twitter_username %>">
<meta name="twitter:title" content="<%= t("views.users.meta.og.title", user: @user.name, community: community_name) %>">
<meta name="twitter:description" content="<%= @user.tag_line %>">
<meta name="twitter:image:src" content="<%= user_social_image_url(@user) %>">
<meta name="twitter:image:src" content="<%= Settings::General.main_social_image %>" />
<% if @stories.any? %>
<%= auto_discovery_link_tag(:rss, app_url("/feed/#{@user.username}"), title: t("views.stories.meta.rss", name: community_name)) %>
<% end %>

View file

@ -4,36 +4,6 @@ describe SocialImageHelper do
let(:user) { create(:user) }
let(:article) { create(:article, main_image: nil) }
describe ".user_social_image_url" do
it "returns social preview path for newer users" do
url = helper.user_social_image_url(user)
expect(url).to eq user_social_preview_url(user, format: :png)
end
it "returns Organization social preview path for Orgs" do
organization = create(:organization)
url = helper.user_social_image_url(organization)
expect(url).to eq organization_social_preview_url(organization, format: :png)
end
it "returns older url2png image if already generated" do
user.updated_at = SocialImageHelper::SOCIAL_PREVIEW_MIGRATION_DATETIME - 1.week
url = helper.user_social_image_url(user)
expect(url).to eq Images::GenerateSocialImage.call(user)
end
it "returns social preview path for newer decorated users" do
url = helper.user_social_image_url(user.decorate)
expect(url).to eq user_social_preview_url(user, format: :png)
end
end
describe ".article_social_image_url" do
it "returns social preview path for newer articles" do
allow(Settings::General).to receive(:app_domain).and_return("hello.com")
@ -52,7 +22,7 @@ describe SocialImageHelper do
end
it "returns older url2png image if already generated" do
article.updated_at = SocialImageHelper::SOCIAL_PREVIEW_MIGRATION_DATETIME - 1.week
article.updated_at = Articles::SocialImage::SOCIAL_PREVIEW_MIGRATION_DATETIME - 1.week
url = helper.article_social_image_url(article)