Skip to content

A platform for community discussion. Free, open, simple.

DEV: use structured data in crawler-linkback-list for referencing only (#16237)

Ayke Halder9f14d643a572
diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb
index aed2a9a7225..f9bb80008f2 100644
--- a/app/views/topics/show.html.erb
+++ b/app/views/topics/show.html.erb
@@ -103,10 +103,7 @@
<% @topic_view.link_counts[post.id].each_with_index do |link, i| %>
<% if link[:reflection] && link[:title].present? %>
<div itemprop='itemListElement' itemscope itemtype='http://schema.org/ListItem'>
- <a href="<%=link[:url]%>" itemscope itemtype='http://schema.org/DiscussionForumPosting' itemprop='item'>
- <meta itemprop='url' content='<%=link[:url]%>'>
- <span itemprop='name'><%=link[:title]%></span>
- </a>
+ <a itemprop='url' href="<%=link[:url]%>"><%=link[:title]%></a>
<meta itemprop='position' content='<%= i+1 %>'>
</div>
<% end %>
diff --git a/spec/views/topics/show.html.erb_spec.rb b/spec/views/topics/show.html.erb_spec.rb
index d5353e80f7f..dda660961d4 100644
--- a/spec/views/topics/show.html.erb_spec.rb
+++ b/spec/views/topics/show.html.erb_spec.rb
@@ -18,4 +18,27 @@ RSpec.describe "topics/show.html.erb" do
%r{<link rel="alternate nofollow" type="application/rss\+xml" title="[^"]+" href="https://www.example.com/test\.rss" />},
)
end
+
+ it "adds sturctured data" do
+ view.stubs(:include_crawler_content?).returns(true)
+ post = Fabricate(:post, topic: topic)
+ TopicLink.create!(
+ topic_id: post.topic_id,
+ post_id: post.id,
+ user_id: post.user_id,
+ url: "https://example.com/",
+ domain: "example.com",
+ link_topic_id: Fabricate(:topic).id,
+ reflection: true,
+ )
+ assign(:topic_view, TopicView.new(topic))
+ assign(:tags, [])
+
+ render template: "topics/show", formats: [:html]
+
+ links_list = Nokogiri::HTML5.fragment(rendered).css(".crawler-linkback-list")
+ first_item = links_list.css('[itemprop="itemListElement"]')
+ expect(first_item.css('[itemprop="position"]')[0]["content"]).to eq("1")
+ expect(first_item.css('[itemprop="url"]')[0]["href"]).to eq("https://example.com/")
+ end
end