Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Add structured data to follow Google's guidelines (#9764)

Dan Ungureanub80128a97340
diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb
index c72ab9a4278..a395d4374e8 100644
--- a/app/views/topics/show.html.erb
+++ b/app/views/topics/show.html.erb
@@ -36,9 +36,17 @@
<%- if include_crawler_content? %>
<% @topic_view.posts.each_with_index do |post, idx| %>
- <div itemscope itemtype='http://schema.org/DiscussionForumPosting' class='topic-body crawler-post'>
- <% if (u = post.user) %>
+ <% if (u = post.user) %>
+ <div itemscope itemtype='http://schema.org/DiscussionForumPosting' class='topic-body crawler-post'>
<div class='crawler-post-meta'>
+ <div itemprop='publisher' itemscope itemtype="http://schema.org/Organization">
+ <meta itemprop='name' content='<%= SiteSetting.company_name.presence || SiteSetting.title %>'>
+ <% if application_logo_url.present? %>
+ <div itemprop='logo' itemscope itemtype="http://schema.org/ImageObject">
+ <meta itemprop='url' content='<%= application_logo_url %>'>
+ </div>
+ <% end %>
+ </div>
<span class="creator" itemprop="author" itemscope itemtype="http://schema.org/Person">
<a itemprop="url" href='<%= Discourse.base_url %>/u/<%= u.username %>'><span itemprop='name'><%= u.username %></span></a>
<%= "(#{u.name})" if (SiteSetting.display_name_on_posts && SiteSetting.enable_names? && !u.name.blank?) %>
@@ -51,6 +59,8 @@
<% end %>
</span>
+ <link itemprop="mainEntityOfPage" href="<%= post.topic.url %>">
+
<% if post.image_url %>
<link itemprop="image" href="<%= Discourse.base_url %><%= post.image_url %>">
<% end %>
@@ -105,9 +115,8 @@
<% end %>
</div>
<% end %>
-
- <% end %>
- </div>
+ </div>
+ <% end %>
<% end %>
<% if @topic_view.prev_page || @topic_view.next_page %>