From 9f14d643a5729dbc541dc5e663a47083788698e9 Mon Sep 17 00:00:00 2001 From: Ayke Halder Date: Mon, 30 Jan 2023 08:26:55 +0100 Subject: [PATCH] DEV: use structured data in crawler-linkback-list for referencing only (#16237) This simplifies the crawler-linkback-list to only be a point of reference to the actual DiscussionForumPosting objects. See "Summary page": https://developers.google.com/search/docs/advanced/structured-data/carousel?hl=en#summary-page > [It] defines an ItemList, where each ListItem has only three properties: @type (set to ListItem), position (the position in the list), and url (the URL of a page with full details about that item). --- app/views/topics/show.html.erb | 5 +---- spec/views/topics/show.html.erb_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) 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? %>
- - - <%=link[:title]%> - +
<% 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{}, ) 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