DEV: use structured data in topic-list for referencing only (#16235)
This simplifies the ItemList 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 Co-authored-by: Bianca Nenciu <nenciu.bianca@gmail.com>
This commit is contained in:
parent
f06be7d295
commit
569299b7a9
|
@ -57,14 +57,9 @@
|
||||||
<% @list.topics.each_with_index do |t,i| %>
|
<% @list.topics.each_with_index do |t,i| %>
|
||||||
<tr class="topic-list-item">
|
<tr class="topic-list-item">
|
||||||
<td class="main-link" itemprop='itemListElement' itemscope itemtype='http://schema.org/ListItem'>
|
<td class="main-link" itemprop='itemListElement' itemscope itemtype='http://schema.org/ListItem'>
|
||||||
<meta itemprop='name' content='<%= t.title %>'>
|
|
||||||
<meta itemprop='url' content='<%= t.url %>'>
|
|
||||||
<% if t.image_url.present? %>
|
|
||||||
<meta itemprop='image' content='<%= t.image_url %>'>
|
|
||||||
<% end %>
|
|
||||||
<meta itemprop='position' content='<%= i + 1 %>'>
|
<meta itemprop='position' content='<%= i + 1 %>'>
|
||||||
<span class="link-top-line">
|
<span class="link-top-line">
|
||||||
<a href='<%= t.url %>' class='title raw-link raw-topic-link'><%= t.title %></a>
|
<a itemprop='url' href='<%= t.url %>' class='title raw-link raw-topic-link'><%= t.title %></a>
|
||||||
</span>
|
</span>
|
||||||
<div class="link-bottom-line">
|
<div class="link-bottom-line">
|
||||||
<% if (!@category || @category.has_children?) && t.category && !t.category.uncategorized? %>
|
<% if (!@category || @category.has_children?) && t.category && !t.category.uncategorized? %>
|
||||||
|
|
|
@ -89,6 +89,16 @@ RSpec.describe ListController do
|
||||||
|
|
||||||
expect(response.body).to have_tag "title", text: "Discourse - Best community"
|
expect(response.body).to have_tag "title", text: "Discourse - Best community"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns structured data" do
|
||||||
|
get "/latest"
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
topic_list = Nokogiri::HTML5(response.body).css('.topic-list')
|
||||||
|
first_item = topic_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(topic.url)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "categories and X" do
|
describe "categories and X" do
|
||||||
|
|
|
@ -4,6 +4,7 @@ require "rails_helper"
|
||||||
|
|
||||||
RSpec.describe "list/list.erb" do
|
RSpec.describe "list/list.erb" do
|
||||||
fab!(:category) { Fabricate(:category) }
|
fab!(:category) { Fabricate(:category) }
|
||||||
|
fab!(:topic) { Fabricate(:topic) }
|
||||||
|
|
||||||
it "add nofollow to RSS alternate link for category" do
|
it "add nofollow to RSS alternate link for category" do
|
||||||
view.stubs(:include_crawler_content?).returns(false)
|
view.stubs(:include_crawler_content?).returns(false)
|
||||||
|
@ -15,4 +16,16 @@ RSpec.describe "list/list.erb" do
|
||||||
expect(view.content_for(:head)).to match(/<link rel="alternate nofollow" type="application\/rss\+xml" title="[^"]+" href="https:\/\/www.example.com\/test\.rss" \/>/)
|
expect(view.content_for(:head)).to match(/<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)
|
||||||
|
topic.posters = []
|
||||||
|
assign(:list, OpenStruct.new(topics: [topic]))
|
||||||
|
|
||||||
|
render template: 'list/list', formats: []
|
||||||
|
|
||||||
|
topic_list = Nokogiri::HTML5::fragment(rendered).css('.topic-list')
|
||||||
|
first_item = topic_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(topic.url)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue