From f97b5de96e19bfab55494bb69f9a2601eb14d1b2 Mon Sep 17 00:00:00 2001 From: Joshua Wehner Date: Tue, 11 Oct 2022 12:28:55 +0200 Subject: [PATCH] Remove social_preview views (except articles) (#18523) * Remove social_preview views (except articles) * Remove unreachable controller actions --- app/controllers/social_previews_controller.rb | 33 ----- app/views/social_previews/comment.html.erb | 135 ------------------ app/views/social_previews/listing.html.erb | 87 ----------- app/views/social_previews/tag.html.erb | 93 ------------ app/views/social_previews/user.html.erb | 128 ----------------- config/routes.rb | 4 - spec/requests/social_previews_spec.rb | 127 ---------------- 7 files changed, 607 deletions(-) delete mode 100644 app/views/social_previews/comment.html.erb delete mode 100644 app/views/social_previews/listing.html.erb delete mode 100644 app/views/social_previews/tag.html.erb delete mode 100644 app/views/social_previews/user.html.erb diff --git a/app/controllers/social_previews_controller.rb b/app/controllers/social_previews_controller.rb index 93ddcdd1b..963381d03 100644 --- a/app/controllers/social_previews_controller.rb +++ b/app/controllers/social_previews_controller.rb @@ -19,39 +19,6 @@ class SocialPreviewsController < ApplicationController set_respond "social_previews/articles/#{template}" end - def user - @user = User.find(params[:id]) - @tag_badges = Badge.where(id: @user.badge_achievements.select(:badge_id)) - set_respond - end - - def listing - @listing = Listing.find(params[:id]).decorate - set_respond - end - - def organization - @user = Organization.find(params[:id]) - @tag_badges = [] # Orgs don't have badges, but they could! - set_respond "user" - end - - def tag - @tag = Tag.find(params[:id]) - @compare_hex = Color::CompareHex.new([@tag.bg_color_hex || "#000000", @tag.text_color_hex || "#ffffff"]) - - set_respond - end - - def comment - @comment = Comment.find(params[:id]) - - badge_ids = Tag.where(name: @comment.commentable&.decorate&.cached_tag_list_array).pluck(:badge_id) - @tag_badges = Badge.where(id: badge_ids) - - set_respond - end - private def set_respond(template = nil) diff --git a/app/views/social_previews/comment.html.erb b/app/views/social_previews/comment.html.erb deleted file mode 100644 index d4f0dbe3f..000000000 --- a/app/views/social_previews/comment.html.erb +++ /dev/null @@ -1,135 +0,0 @@ -<% accent_color = Color::CompareHex.new([user_colors(@comment.user)[:bg], user_colors(@comment.user)[:text]]).biggest %> -<% dark_color = Color::CompareHex.new([user_colors(@comment.user)[:bg], user_colors(@comment.user)[:text]]).brightness(0.8) %> - - -
-
- <% if @comment.title.size < 15 %> - <% font_size = 12 %> - <% elsif @comment.title.size < 30 %> - <% font_size = 9.2 %> - <% elsif @comment.title.size < 50 %> - <% font_size = 8.3 %> - <% else %> - <% font_size = 15 - (((@comment.title.size**0.92) + 85) / 16) %> - <% end %> -
-

re: <%= @comment.commentable&.title %>

-

<%= @comment.title %>

-
-
- - <%= truncate @comment.user.name, length: 28 %>・<%= @comment.readable_publish_date %> -
-
- <% @tag_badges.each do |badge| %> - <%# Use a seed in Random so we don't break cache on every render %> - <% not_so_rand = Random.new(badge.id + @comment.id) %> - - <% end %> - -
-
-
diff --git a/app/views/social_previews/listing.html.erb b/app/views/social_previews/listing.html.erb deleted file mode 100644 index 12cb4d14c..000000000 --- a/app/views/social_previews/listing.html.erb +++ /dev/null @@ -1,87 +0,0 @@ - -
-
-
- <% font_size = @listing.title.length > 65 ? 4 : 5 %> -

<%= @listing.title %>

-
-
- <%= sanitize_rendered_markdown(@listing.processed_html) %> -
-
- <%= @listing.social_preview_category %> -
- -
-
diff --git a/app/views/social_previews/tag.html.erb b/app/views/social_previews/tag.html.erb deleted file mode 100644 index 398783b1e..000000000 --- a/app/views/social_previews/tag.html.erb +++ /dev/null @@ -1,93 +0,0 @@ -<% accent_color = @compare_hex.biggest %> -<% color = @compare_hex.brightness(1.4) %> -<% dark_color = @compare_hex.brightness(0.7) %> -<% not_so_rand = Random.new(@tag.id) # Using ID as seed ensures we get the same "random" numbers on each page load, Improves caching %> - -
-
-

- #<%= @tag.name %> -

- <% if @tag.pretty_name %> -

- <%= @tag.pretty_name %> -

- <% end %> -
- <% if @tag.badge_id %> - <%# Use a seed in Random so we don't break cache on every render %> - <% @badge = Badge.find(@tag.badge_id) %> - <% not_so_rand = Random.new(@badge.id) %> - - <% end %> - -
-
-
- diff --git a/app/views/social_previews/user.html.erb b/app/views/social_previews/user.html.erb deleted file mode 100644 index 8ebe9bf76..000000000 --- a/app/views/social_previews/user.html.erb +++ /dev/null @@ -1,128 +0,0 @@ -<% accent_color = Color::CompareHex.new([user_colors(@user)[:bg], user_colors(@user)[:text]]).biggest %> -<% dark_color = Color::CompareHex.new([user_colors(@user)[:bg], user_colors(@user)[:text]]).brightness(0.8) %> - -
-
-
- <% if @user.name.size < 14 %> - <% font_size = 8.3 %> - <% elsif @user.name.size < 20 %> - <% font_size = 6.4 %> - <% else %> - <% font_size = 4.6 %> - <% end %> -

- <%= @user.name %> profile image - <%= truncate @user.name, length: 32 %> -
- @<%= @user.username %> -

-
-
- <% @tag_badges.each do |badge| %> - <%# Use a seed in Random so we don't break cache on every render %> - <% not_so_rand = Random.new(badge.id + @user.id) %> - - <% end %> - -
-
-
diff --git a/config/routes.rb b/config/routes.rb index 17fbf67d1..32fdf3e2a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -182,10 +182,6 @@ Rails.application.routes.draw do get "/internal/:path", to: redirect("/admin/%{path}") get "/social_previews/article/:id", to: "social_previews#article", as: :article_social_preview - get "/social_previews/user/:id", to: "social_previews#user", as: :user_social_preview - get "/social_previews/organization/:id", to: "social_previews#organization", as: :organization_social_preview - get "/social_previews/tag/:id", to: "social_previews#tag", as: :tag_social_preview - get "/social_previews/comment/:id", to: "social_previews#comment", as: :comment_social_preview get "/async_info/base_data", controller: "async_info#base_data", defaults: { format: :json } diff --git a/spec/requests/social_previews_spec.rb b/spec/requests/social_previews_spec.rb index 9f67a4a6b..abb63e9be 100644 --- a/spec/requests/social_previews_spec.rb +++ b/spec/requests/social_previews_spec.rb @@ -38,131 +38,4 @@ RSpec.describe "SocialPreviews", type: :request do expect(response).to redirect_to(image_url) end end - - describe "GET /social_previews/user/:id" do - it "renders proper user name" do - get "/social_previews/user/#{user.id}" - expect(response.body).to include CGI.escapeHTML(user.name) - end - - it "renders consistent HTML between requests" do - create(:badge_achievement, user: user) - - # We use the HTML for caching. It needs to be deterministic (if data is unchanged, the HTML should be the same) - get "/social_previews/user/#{user.id}" - first_request_body = response.body - - get "/social_previews/user/#{user.id}" - second_request_body = response.body - - expect(first_request_body).to eq second_request_body - end - - it "renders an image when requested and redirects to image url" do - get "/social_previews/user/#{user.id}.png" - - expect(response).to redirect_to(image_url) - end - end - - describe "GET /social_previews/organization/:id" do - it "renders proper organization name" do - get "/social_previews/organization/#{organization.id}" - expect(response.body).to include CGI.escapeHTML(organization.name) - end - - it "renders consistent HTML between requests" do - # We use the HTML for caching. It needs to be deterministic (if data is unchanged, the HTML should be the same) - get "/social_previews/organization/#{organization.id}" - first_request_body = response.body - - get "/social_previews/organization/#{organization.id}" - second_request_body = response.body - - expect(first_request_body).to eq second_request_body - end - - it "renders an image when requested and redirects to image url" do - get "/social_previews/organization/#{organization.id}.png" - - expect(response).to redirect_to(image_url) - end - end - - describe "GET /social_previews/tag/:id" do - it "renders proper tag name" do - get "/social_previews/tag/#{tag.id}" - expect(response.body).to include CGI.escapeHTML(tag.name) - end - - it "renders consistent HTML between requests" do - # We use the HTML for caching. It needs to be deterministic (if data is unchanged, the HTML should be the same) - get "/social_previews/tag/#{tag.id}" - first_request_body = response.body - - get "/social_previews/tag/#{tag.id}" - second_request_body = response.body - - expect(first_request_body).to eq second_request_body - end - - it "renders an image when requested and redirects to image url" do - get "/social_previews/tag/#{tag.id}.png" - - expect(response).to redirect_to(image_url) - end - end - - describe "GET /social_previews/listing/:id" do - let(:listing) { create(:listing, user_id: user.id) } - - it "renders pretty category name" do - get "/social_previews/listing/#{listing.id}" - expect(response.body).to include CGI.escapeHTML("Education") - end - - it "renders consistent HTML between requests" do - # We use the HTML for caching. It needs to be deterministic (if data is unchanged, the HTML should be the same) - get "/social_previews/listing/#{listing.id}" - first_request_body = response.body - - get "/social_previews/listing/#{listing.id}" - second_request_body = response.body - - expect(first_request_body).to eq second_request_body - end - - it "renders and image when requested and redirects to image url" do - get "/social_previews/listing/#{listing.id}.png" - expect(response).to redirect_to(image_url) - end - end - - describe "GET /social_previews/comment/:id" do - it "renders proper comment name" do - get "/social_previews/comment/#{comment.id}" - expect(response.body).to include CGI.escapeHTML(comment.title) - end - - it "renders associated article name" do - get "/social_previews/comment/#{comment.id}" - expect(response.body).to include CGI.escapeHTML(comment.commentable.title) - end - - it "renders consistent HTML between requests" do - # We use the HTML for caching. It needs to be deterministic (if data is unchanged, the HTML should be the same) - get "/social_previews/comment/#{comment.id}" - first_request_body = response.body - - get "/social_previews/comment/#{comment.id}" - second_request_body = response.body - - expect(first_request_body).to eq second_request_body - end - - it "renders and image when requested and redirects to image url" do - get "/social_previews/comment/#{comment.id}.png" - expect(response).to redirect_to(image_url) - end - end end