diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 540dd2f27..46ac48077 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -371,11 +371,7 @@ class StoriesController < ApplicationController "@id": URL.article(@article) }, "url": URL.article(@article), - "image": [ - ApplicationController.helpers.article_social_image_url(@article, width: 1080, height: 1080), - ApplicationController.helpers.article_social_image_url(@article, width: 1280, height: 720), - ApplicationController.helpers.article_social_image_url(@article, width: 1600, height: 900), - ], + "image": seo_optimized_images, "publisher": { "@context": "http://schema.org", "@type": "Organization", @@ -400,6 +396,15 @@ class StoriesController < ApplicationController } end + def seo_optimized_images + # This array of images exists for SEO optimization purposes. + # For more info on this structure, please refer to this documentation: + # https://developers.google.com/search/docs/data-types/article + [ApplicationController.helpers.article_social_image_url(@article, width: 1080, height: 1080), + ApplicationController.helpers.article_social_image_url(@article, width: 1280, height: 720), + ApplicationController.helpers.article_social_image_url(@article, width: 1600, height: 900)] + end + def set_organization_json_ld @organization_json_ld = { "@context": "http://schema.org", diff --git a/spec/requests/stories_show_spec.rb b/spec/requests/stories_show_spec.rb index 6ff6d4a37..b0e973106 100644 --- a/spec/requests/stories_show_spec.rb +++ b/spec/requests/stories_show_spec.rb @@ -33,7 +33,7 @@ RSpec.describe "StoriesShow", type: :request do expect(response.body).to include html_variant.html end - it "Does not render variant when no variants published" do + it "does not render variant when no variants published" do html_variant = create(:html_variant, published: false, approved: true) get article.path + "?variant_version=1" expect(response.body).not_to include html_variant.html @@ -54,14 +54,14 @@ RSpec.describe "StoriesShow", type: :request do expect(response.body).to include html_variant.html end - it "Does not render below article html variant for short article" do + it "does not render below article html variant for short article" do html_variant = create(:html_variant, published: true, approved: true, group: "article_show_below_article_cta") article.update_column(:body_markdown, rand(36**100).to_s(36).to_s) # ensure too short get article.path + "?variant_version=0" expect(response.body).not_to include html_variant.html end - it "Does not render below article variant when no variants published" do + it "does not render below article variant when no variants published" do html_variant = create(:html_variant, published: false, approved: true, group: "article_show_below_article_cta") get article.path + "?variant_version=0" expect(response.body).not_to include html_variant.html @@ -85,14 +85,14 @@ RSpec.describe "StoriesShow", type: :request do expect(response.body).to include "title" end - it "redirect to appropriate page if user changes username" do + it "redirects to appropriate page if user changes username" do old_username = user.username user.update(username: "new_hotness_#{rand(10_000)}") get "/#{old_username}/#{article.slug}" expect(response.body).to redirect_to("/#{user.username}/#{article.slug}") end - it "redirect to appropriate page if user changes username twice" do + it "redirects to appropriate page if user changes username twice" do old_username = user.username user.update(username: "new_hotness_#{rand(10_000)}") user.update(username: "new_new_username_#{rand(10_000)}") @@ -100,7 +100,7 @@ RSpec.describe "StoriesShow", type: :request do expect(response.body).to redirect_to("/#{user.username}/#{article.slug}") end - it "redirect to appropriate page if user changes username twice and go to middle username" do + it "redirects to appropriate page if user changes username twice and go to middle username" do user.update(username: "new_hotness_#{rand(10_000)}") middle_username = user.username user.update(username: "new_new_username_#{rand(10_000)}") @@ -114,7 +114,7 @@ RSpec.describe "StoriesShow", type: :request do expect(response.body).to include('"canonical" href="' + article.canonical_url.to_s + '"') end - it "shodoes not render canonical url when not on article model" do + it "does not render canonical url when not on article model" do article = create(:article, with_canonical_url: false) get article.path expect(response.body).not_to include('"canonical" href="' + article.canonical_url.to_s + '"')