Skip to content

Commit

Permalink
FIX: use schema.org's BreadcrumList
Browse files Browse the repository at this point in the history
The data-vocabulary.org schema is being deprecated.
We're now using the BreadcrumList data from the latest and greatest schema.org.

FIX: categories_breadcrumb helper to support more than 2 levels of categories.
  • Loading branch information
ZogStriP committed Jan 21, 2020
1 parent 89bd7ba commit 96b64df
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
8 changes: 4 additions & 4 deletions app/helpers/topics_helper.rb
Expand Up @@ -9,13 +9,13 @@ def render_topic_title(topic)

def categories_breadcrumb(topic)
breadcrumb = []

category = topic.category

if category && !category.uncategorized?
if (parent = category.parent_category)
breadcrumb.push url: parent.url, name: parent.name
breadcrumb.push(url: category.url, name: category.name)
while category = category.parent_category
breadcrumb.prepend(url: category.url, name: category.name)
end
breadcrumb.push url: category.url, name: category.name
end

Plugin::Filter.apply(:topic_categories_breadcrumb, topic, breadcrumb)
Expand Down
22 changes: 10 additions & 12 deletions app/views/topics/show.html.erb
Expand Up @@ -3,18 +3,16 @@
<%= render_topic_title(@topic_view.topic) %>
</h1>

<% @breadcrumbs = categories_breadcrumb(@topic_view.topic)
if @breadcrumbs.present? %>
<div id='breadcrumbs'>
<% @breadcrumbs.each_with_index do |c,i| %>
<div id="breadcrumb-<%=i%>" itemscope itemtype="http://data-vocabulary.org/Breadcrumb"
<%-if (i+1) < @breadcrumbs.length%>
itemref="breadcrumb-<%=(i+1)%>"
<%-end%>>
<a href="<%=c[:url]%>" itemprop="url" class='badge-wrapper bullet'>
<% @breadcrumbs = categories_breadcrumb(@topic_view.topic) %>
<% if @breadcrumbs.present? %>
<div id="breadcrumbs" itemscope itemtype="http://schema.org/BreadcrumbList">
<% @breadcrumbs.each_with_index do |c, i| %>
<div itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
<a href="<%= Discourse.base_url %><%= c[:url] %>" class="badge-wrapper bullet" itemprop="item">
<span class="badge-category-bg"></span>
<span itemprop="title" class='category-title'><%=c[:name]%></span>
<span class="category-title" itemprop="name"><%= c[:name] %></span>
</a>
<meta itemprop="position" content="<%= i + 1 %>" />
</div>
<% end %>
</div>
Expand All @@ -26,7 +24,7 @@
<div class='crawler-tags-list' itemscope itemtype='http://schema.org/DiscussionForumPosting'>
<% @tags.each_with_index do |tag, i| %>
<div itemprop='keywords'>
<a href='<%= "#{Discourse.base_url}/tag/#{tag.name}" %>' rel="tag">
<a href='<%= "#{Discourse.base_url}/tag/#{tag.name}" %>' rel="tag">
<span itemprop='headline'><%= tag.name -%></span>
</a>
</div>
Expand All @@ -44,7 +42,7 @@
<% if (u = post.user) %>
<div class='crawler-post-meta'>
<span class="creator" itemprop="author" itemscope itemtype="http://schema.org/Person">
<a itemprop="url" href='<%= Discourse.base_uri %>/u/<%= u.username %>'><span itemprop='name'><%= u.username %></span></a>
<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?) %>
<%
post_custom_fields = @topic_view.post_custom_fields[post.id] || {}
Expand Down

3 comments on commit 96b64df

@discoursebot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/breadcrumbs-issues-detected-on-search-console/139351/2

@discoursebot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/warning-breadcrumbs-issue-and-schema-deprecated/139328/11

@discoursebot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/change-iso-code-for-language-on-single-page/107736/20

Please sign in to comment.