Skip to content
Snippets Groups Projects

Add schema markup to breadcrumb

Merged Francisco Javier López requested to merge 36844-fj-add-schema-to-breadcrumb-json into master
All threads resolved!
Files
6
@@ -34,14 +34,16 @@ def add_to_breadcrumb_dropdown(link, location: :before)
@@ -34,14 +34,16 @@ def add_to_breadcrumb_dropdown(link, location: :before)
end
end
def push_to_schema_breadcrumb(text, link)
def push_to_schema_breadcrumb(text, link)
schema_breadcrumb_list.push(schema_list_item(text, link, schema_breadcrumb_list.size + 1))
list_item = schema_list_item(text, link, schema_breadcrumb_list.size + 1)
 
 
schema_breadcrumb_list.push(list_item)
end
end
def schema_breadcrumb_json
def schema_breadcrumb_json
{
{
'@context': 'https://schema.org',
'@context': 'https://schema.org',
'@type': 'BreadcrumbList',
'@type': 'BreadcrumbList',
'itemListElement': schema_breadcrumb_list
'itemListElement': build_item_list_elements
}.to_json
}.to_json
end
end
@@ -51,6 +53,19 @@ def schema_breadcrumb_list
@@ -51,6 +53,19 @@ def schema_breadcrumb_list
@schema_breadcrumb_list ||= []
@schema_breadcrumb_list ||= []
end
end
 
def build_item_list_elements
 
return @schema_breadcrumb_list unless @breadcrumbs_extra_links&.any?
 
 
last_element = schema_breadcrumb_list.pop
 
 
@breadcrumbs_extra_links.each do |el|
 
push_to_schema_breadcrumb(el[:text], el[:link])
 
end
 
 
last_element['position'] = schema_breadcrumb_list.last['position'] + 1
 
schema_breadcrumb_list.push(last_element)
 
end
 
def schema_list_item(text, link, position)
def schema_list_item(text, link, position)
{
{
'@type' => 'ListItem',
'@type' => 'ListItem',
Loading