From 7a867d6133406bc2e2a28c96e694708adf0e377f Mon Sep 17 00:00:00 2001 From: Ben Halpern Date: Fri, 27 Dec 2019 10:58:23 -0500 Subject: [PATCH] Add canonical url to posts even if internal nav (#5227) [deploy] * Add canonical url to posts even if internal nav * Render to meta if not internal --- app/views/articles/show.html.erb | 10 ++++------ spec/requests/stories_show_spec.rb | 12 ++++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/views/articles/show.html.erb b/app/views/articles/show.html.erb index 80d2a2a45..113558e49 100644 --- a/app/views/articles/show.html.erb +++ b/app/views/articles/show.html.erb @@ -36,13 +36,11 @@ <% end %> <% end %> -<% if !internal_navigation? %> +<% if internal_navigation? %> + " /> +<% else %> <%= content_for :page_meta do %> - <% if @article.canonical_url.present? %> - - <% else %> - - <% end %> + " /> "> diff --git a/spec/requests/stories_show_spec.rb b/spec/requests/stories_show_spec.rb index a4c2c65ca..08f847f3d 100644 --- a/spec/requests/stories_show_spec.rb +++ b/spec/requests/stories_show_spec.rb @@ -107,6 +107,18 @@ RSpec.describe "StoriesShow", type: :request do get "/#{middle_username}/#{article.slug}" expect(response.body).to redirect_to("/#{user.username}/#{article.slug}") end + + it "renders canonical url when exists" do + article = create(:article, with_canonical_url: true) + get article.path + 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 + article = create(:article, with_canonical_url: false) + get article.path + expect(response.body).not_to include('"canonical" href="' + article.canonical_url.to_s + '"') + end end describe "GET /:username (org)" do