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).
This commit is contained in:
Ayke Halder 2023-01-30 08:26:55 +01:00 committed by GitHub
parent 137dbaf0dc
commit 9f14d643a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View File

@ -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 %>

View File

@ -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