Display 'Originally published' for canonical URLs (#8761)

This commit is contained in:
Michael Kohl 2020-06-18 19:10:47 +07:00 committed by GitHub
parent 2fff21f652
commit 158b3f1307
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View file

@ -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)

View file

@ -166,8 +166,8 @@
<em>
Originally published at
<a href="<%= @article.canonical_url || @article.feed_source_url %>" style="color:#1395b8"><%= get_host_without_www(@article.canonical_url || @article.feed_source_url) %></a>
on
<% if @article.crossposted_at %>
on
<time datetime="<%= (@article.originally_published_at || @article.published_at)&.utc&.iso8601 %>"><%= (@article.originally_published_at || @article.published_at)&.strftime("%b %d, %Y") %></time>
<% end %>
</em>

View file

@ -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