FIX: Multiple schema.org improvements

* Do not show "Uncategorized" category in topics list.
* Use "BreadcrumbList" only if topic is in a category.
* Add tags list as keywords to the first post.
* Add "dateModified" even if it is the same with "datePublished".
* Show "crawler-linkback-list" only if there are links to be shown.
This commit is contained in:
Dan Ungureanu 2020-05-11 20:37:50 +03:00
parent 0deb05740f
commit 141f16eb6b
No known key found for this signature in database
GPG Key ID: 0AA2A00D6ACC8B84
3 changed files with 29 additions and 14 deletions

View File

@ -33,6 +33,10 @@ body.crawler {
margin-top: 4em; margin-top: 4em;
} }
.topic-category {
display: inline;
}
.discourse-tags { .discourse-tags {
color: $primary-medium; color: $primary-medium;
} }

View File

@ -67,7 +67,7 @@
<a href='<%= t.url %>' class='title raw-link raw-topic-link'><%= t.title %></a> <a 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 %> <% if (!@category || @category.has_children?) && t.category && !t.category.uncategorized? %>
<a href='<%= t.category.url %>' class='badge-wrapper bullet'> <a href='<%= t.category.url %>' class='badge-wrapper bullet'>
<span class='badge-category-bg' style='background-color: #<%= t.category.color %>'></span> <span class='badge-category-bg' style='background-color: #<%= t.category.color %>'></span>
<span class='badge-category clear-badge'> <span class='badge-category clear-badge'>

View File

@ -4,26 +4,29 @@
<%= render_topic_title(@topic_view.topic) %> <%= render_topic_title(@topic_view.topic) %>
</h1> </h1>
<% if @breadcrumbs.present? || @tags.present? %> <% if @breadcrumbs.present? %>
<div class="topic-category" itemscope itemtype="http://schema.org/BreadcrumbList"> <div class="topic-category" itemscope itemtype="http://schema.org/BreadcrumbList">
<% @breadcrumbs.each_with_index do |c, i| %> <% @breadcrumbs.each_with_index do |c, i| %>
<span itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"> <span itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
<a href="<%= Discourse.base_url %><%= c[:url] %>" class="badge-wrapper bullet" itemprop="item"> <a href="<%= Discourse.base_url %><%= c[:url] %>" class="badge-wrapper bullet" itemprop="item">
<span class="badge-category-bg" style='background-color: #<%= c[:color] %>'></span> <span class='badge-category-bg' style='background-color: #<%= c[:color] %>'></span>
<span class="category-name" itemprop="name"><%= c[:name] %></span> <span class='badge-category clear-badge'>
<span class='category-name' itemprop='name'><%= c[:name] %></span>
</span>
</a> </a>
<meta itemprop="position" content="<%= i + 1 %>" /> <meta itemprop="position" content="<%= i + 1 %>" />
</span> </span>
<% end %> <% end %>
</div>
<% end %>
<% if @tags.present? %> <% if @tags.present? %>
<meta itemprop='keywords' content='<%= @tags.map(&:name).join(', ') %>'> <div class="topic-category">
<div class='discourse-tags list-tags'> <div class='discourse-tags list-tags'>
<% @tags.each_with_index do |tag, i| %> <% @tags.each_with_index do |tag, i| %>
<a href='<%= "#{Discourse.base_url}/tag/#{tag.name}" %>' class='discourse-tag' rel="tag"><%= tag.name -%></a><% if i < @tags.size - 1 %>, <% end %> <a href='<%= "#{Discourse.base_url}/tag/#{tag.name}" %>' class='discourse-tag' rel="tag"><%= tag.name -%></a><% if i < @tags.size - 1 %>, <% end %>
<% end %> <% end %>
</div> </div>
<% end %>
</div> </div>
<% end %> <% end %>
</div> </div>
@ -32,7 +35,7 @@
<%- if include_crawler_content? %> <%- if include_crawler_content? %>
<% @topic_view.posts.each do |post| %> <% @topic_view.posts.each_with_index do |post, idx| %>
<div itemscope itemtype='http://schema.org/DiscussionForumPosting' class='topic-body crawler-post'> <div itemscope itemtype='http://schema.org/DiscussionForumPosting' class='topic-body crawler-post'>
<% if (u = post.user) %> <% if (u = post.user) %>
<div class='crawler-post-meta'> <div class='crawler-post-meta'>
@ -48,6 +51,10 @@
<% end %> <% end %>
</span> </span>
<% if post.image_url %>
<link itemprop="image" href="<%= Discourse.base_url %><%= post.image_url %>">
<% end %>
<span class="crawler-post-infos"> <span class="crawler-post-infos">
<% if post.updated_at > post.created_at %> <% if post.updated_at > post.created_at %>
<meta itemprop='datePublished' content='<%= post.created_at.to_formatted_s(:iso8601) %>'> <meta itemprop='datePublished' content='<%= post.created_at.to_formatted_s(:iso8601) %>'>
@ -58,6 +65,7 @@
<time itemprop='datePublished' datetime='<%= post.created_at.to_formatted_s(:iso8601) %>' class='post-time'> <time itemprop='datePublished' datetime='<%= post.created_at.to_formatted_s(:iso8601) %>' class='post-time'>
<%= l post.created_at, format: :long %> <%= l post.created_at, format: :long %>
</time> </time>
<meta itemprop='dateModified' content='<%= post.updated_at.to_formatted_s(:iso8601) %>'>
<% end %> <% end %>
<span itemprop='position'>#<%= post.post_number %></span> <span itemprop='position'>#<%= post.post_number %></span>
</span> </span>
@ -67,6 +75,9 @@
</div> </div>
<meta itemprop='headline' content='<%= @topic_view.title %>'> <meta itemprop='headline' content='<%= @topic_view.title %>'>
<% if idx == 0 %>
<meta itemprop='keywords' content='<%= @tags.map(&:name).join(', ') %>'>
<% end %>
<div itemprop="interactionStatistic" itemscope itemtype="http://schema.org/InteractionCounter"> <div itemprop="interactionStatistic" itemscope itemtype="http://schema.org/InteractionCounter">
<meta itemprop="interactionType" content="http://schema.org/LikeAction"/> <meta itemprop="interactionType" content="http://schema.org/LikeAction"/>
@ -79,7 +90,7 @@
<meta itemprop="userInteractionCount" content="<%= post.reply_count %>" /> <meta itemprop="userInteractionCount" content="<%= post.reply_count %>" />
</div> </div>
<% if @topic_view.link_counts[post.id] && @topic_view.link_counts[post.id].length > 0 %> <% if @topic_view.link_counts[post.id] && @topic_view.link_counts[post.id].filter { |l| l[:reflection] }.length > 0 %>
<div class='crawler-linkback-list' itemscope itemtype='http://schema.org/ItemList'> <div class='crawler-linkback-list' itemscope itemtype='http://schema.org/ItemList'>
<% @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? %>