Display 'Originally published' for canonical URLs (#8761)
This commit is contained in:
parent
2fff21f652
commit
158b3f1307
3 changed files with 11 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue