From 158b3f130756774bbe20da6fd069c7d569ed1403 Mon Sep 17 00:00:00 2001 From: Michael Kohl Date: Thu, 18 Jun 2020 19:10:47 +0700 Subject: [PATCH] Display 'Originally published' for canonical URLs (#8761) --- app/helpers/articles_helper.rb | 5 +++-- app/views/articles/show.html.erb | 2 +- spec/views/articles_spec.rb | 7 +++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/helpers/articles_helper.rb b/app/helpers/articles_helper.rb index b6dc1a5f0..6ae898fc6 100644 --- a/app/helpers/articles_helper.rb +++ b/app/helpers/articles_helper.rb @@ -41,11 +41,12 @@ module ArticlesHelper end def should_show_crossposted_on?(article) - article.crossposted_at && + article.canonical_url || + (article.crossposted_at && article.published_from_feed && article.published && article.published_at && - article.feed_source_url.present? + article.feed_source_url.present?) end def get_host_without_www(url) diff --git a/app/views/articles/show.html.erb b/app/views/articles/show.html.erb index 5cec4c74c..178c6ce06 100644 --- a/app/views/articles/show.html.erb +++ b/app/views/articles/show.html.erb @@ -166,8 +166,8 @@ Originally published at <%= get_host_without_www(@article.canonical_url || @article.feed_source_url) %> - on <% if @article.crossposted_at %> + on <% end %> diff --git a/spec/views/articles_spec.rb b/spec/views/articles_spec.rb index 2c214c43a..ebc66c111 100644 --- a/spec/views/articles_spec.rb +++ b/spec/views/articles_spec.rb @@ -47,4 +47,11 @@ RSpec.describe "articles/show", type: :view do expect(rendered).to have_css("form#new_comment") expect(rendered).to have_css("input#submit-button") end + + it "shows a note about the canonical URL" do + allow(article1).to receive(:canonical_url).and_return("https://example.com/lamas") + render + expect(rendered).to have_text("Originally published at") + expect(rendered).to have_text("example.com") + end end