Show canonical URL on article even after it has been updated (#11256)
* Show canonical URL on article even after it has been updated * Refactor canonical URL fix * Clean up canonical URL code * Clean up canonical URL code
This commit is contained in:
parent
824e9a13cb
commit
bae898ed1a
2 changed files with 15 additions and 4 deletions
|
|
@ -159,18 +159,19 @@
|
|||
<em>with <%= @article.co_author_name_and_path.html_safe %></em>
|
||||
<% end %>
|
||||
|
||||
<% if should_show_updated_on?(@article) %>
|
||||
<em>Updated on <time datetime="<%= @article.edited_at&.utc&.iso8601 %>"><%= @article.edited_at&.strftime("%b %d, %Y") %></time></em>
|
||||
<% elsif should_show_crossposted_on?(@article) %>
|
||||
<% if should_show_crossposted_on?(@article) %>
|
||||
<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>
|
||||
<% 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>
|
||||
<%= local_date(@article.originally_published_at || @article.published_at, show_year: (@article.originally_published_at || @article.published_at).year != Time.current.year) %>
|
||||
<% end %>
|
||||
</em>
|
||||
<% end %>
|
||||
<% if should_show_updated_on?(@article) %>
|
||||
・<em>Updated on <%= local_date(@article.edited_at, show_year: @article.edited_at.year != Time.current.year) %></em>
|
||||
<% end %>
|
||||
|
||||
<span class="mr-4">・<%= @article.reading_time < 1 ? 1 : @article.reading_time %> min read</span>
|
||||
</span>
|
||||
|
|
|
|||
|
|
@ -54,4 +54,14 @@ RSpec.describe "articles/show", type: :view do
|
|||
expect(rendered).to have_text("Originally published at")
|
||||
expect(rendered).to have_text("example.com")
|
||||
end
|
||||
|
||||
it "shows a note about the canonical URL after edit" do
|
||||
allow(article1).to receive(:canonical_url).and_return("https://example.com/lamas")
|
||||
allow(article1).to receive(:published_at).and_return(Time.zone.at(0))
|
||||
allow(article1).to receive(:edited_at).and_return(Time.current)
|
||||
render
|
||||
expect(rendered).to have_text("Originally published at")
|
||||
expect(rendered).to have_text("example.com")
|
||||
expect(rendered).to have_text("Updated on")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue