3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'app/helpers/spree/posts_helper.rb', line 3
def posts_json_ld_breadcrumbs(post)
json_ld = {
'@context' => 'https://schema.org',
'@type' => 'BreadcrumbList',
'itemListElement' => [
{
'@type' => 'ListItem',
'position' => 1,
'name' => Spree.t(:homepage),
'item' => spree.root_url(host: current_store.url_or_custom_domain)
},
{
'@type' => 'ListItem',
'position' => 2,
'name' => Spree.t(:blog),
'item' => spree.posts_url(host: current_store.url_or_custom_domain)
}
]
}
post_breadcrumb = { '@type' => 'ListItem', 'name' => post.title }
post_category = post.post_category
if post_category.present?
json_ld['itemListElement'] << {
'@type' => 'ListItem',
'position' => 3,
'name' => post_category.title,
'item' => spree.category_posts_url(category_id: post.post_category.slug, host: current_store.url_or_custom_domain)
}
json_ld['itemListElement'] << post_breadcrumb.merge('position' => 4)
else
json_ld['itemListElement'] << post_breadcrumb.merge('position' => 3)
end
json_ld
end
|