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:
parent
137dbaf0dc
commit
9f14d643a5
|
@ -103,10 +103,7 @@
|
||||||
<% @topic_view.link_counts[post.id].each_with_index do |link, i| %>
|
<% @topic_view.link_counts[post.id].each_with_index do |link, i| %>
|
||||||
<% if link[:reflection] && link[:title].present? %>
|
<% if link[:reflection] && link[:title].present? %>
|
||||||
<div itemprop='itemListElement' itemscope itemtype='http://schema.org/ListItem'>
|
<div itemprop='itemListElement' itemscope itemtype='http://schema.org/ListItem'>
|
||||||
<a href="<%=link[:url]%>" itemscope itemtype='http://schema.org/DiscussionForumPosting' itemprop='item'>
|
<a itemprop='url' href="<%=link[:url]%>"><%=link[:title]%></a>
|
||||||
<meta itemprop='url' content='<%=link[:url]%>'>
|
|
||||||
<span itemprop='name'><%=link[:title]%></span>
|
|
||||||
</a>
|
|
||||||
<meta itemprop='position' content='<%= i+1 %>'>
|
<meta itemprop='position' content='<%= i+1 %>'>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -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" />},
|
%r{<link rel="alternate nofollow" type="application/rss\+xml" title="[^"]+" href="https://www.example.com/test\.rss" />},
|
||||||
)
|
)
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue