From bae898ed1ac62a3fdef0dccb9d81b5fb2ec7a49e Mon Sep 17 00:00:00 2001
From: n martin <9145247+meisekimiu@users.noreply.github.com>
Date: Tue, 10 Nov 2020 05:30:21 -0700
Subject: [PATCH] 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
---
app/views/articles/show.html.erb | 9 +++++----
spec/views/articles_spec.rb | 10 ++++++++++
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/app/views/articles/show.html.erb b/app/views/articles/show.html.erb
index 6d2664a30..eac87fd23 100644
--- a/app/views/articles/show.html.erb
+++ b/app/views/articles/show.html.erb
@@ -159,18 +159,19 @@
with <%= @article.co_author_name_and_path.html_safe %>
<% end %>
- <% if should_show_updated_on?(@article) %>
- Updated on
- <% elsif should_show_crossposted_on?(@article) %>
+ <% if should_show_crossposted_on?(@article) %>
Originally published at
<%= get_host_without_www(@article.canonical_url || @article.feed_source_url) %>
<% if @article.crossposted_at %>
on
-
+ <%= local_date(@article.originally_published_at || @article.published_at, show_year: (@article.originally_published_at || @article.published_at).year != Time.current.year) %>
<% end %>
<% end %>
+ <% if should_show_updated_on?(@article) %>
+ ・Updated on <%= local_date(@article.edited_at, show_year: @article.edited_at.year != Time.current.year) %>
+ <% end %>
・<%= @article.reading_time < 1 ? 1 : @article.reading_time %> min read
diff --git a/spec/views/articles_spec.rb b/spec/views/articles_spec.rb
index df6677cbf..eaf8a2a05 100644
--- a/spec/views/articles_spec.rb
+++ b/spec/views/articles_spec.rb
@@ -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