|
<%# |
|
# Want to add fancy Bread Crumbs to your search results page? |
|
# https://developers.google.com/search/docs/data-types/breadcrumb |
|
|
|
# Here's a simple layout I made to make this easy to apply across all search engine findable content. |
|
|
|
# Just use this in the bottom of your show page or index pages/views. |
|
|
|
# To use this, just pass in an array of hashes, each hash with {name: , slug: }. |
|
|
|
# Each tier of slug should contain the full uri with no leading slash, instead of just the object's slug. |
|
# Examples: |
|
# yourwebsite.com/ use: path = nil |
|
# yourwebsite.com/blog use: path = {obj: path = [{name: 'Blog', slug: 'blog'} ]} |
|
# yourwebsite.com/blog/post-about-something use: path = {obj: path = [{name: 'Blog', slug: 'blog'},{name: @post.title, slug: 'blog/' + @post.slug }]} |
|
|
|
|
|
# # This will produce a single breadcrumb for your home page. |
|
# render ('schema-path'), obj: paths = nil |
|
|
|
# # This will produce a 2 tier breadcrumb for your blog page. |
|
# render ('schema-path'), obj: paths = [ { name: 'Our Blog Posts', slug: 'blog' } ] |
|
|
|
# # Use the view instances variables |
|
# render ('schema-path'), obj: paths = [ { name: 'Our Blog Posts', slug: 'blog' }, { name: @post.title, slug: 'blog/' + @post.slug} ] } |
|
|
|
# There are no limits to the depth of the bread crumbs, but I suggest keeping you're public url structure under 4 tiers when possible. |
|
-%> |
|
<script type="application/ld+json"> |
|
{ |
|
"@context": "https://schema.org", |
|
"@type": "BreadcrumbList", |
|
"itemListElement": [{ |
|
"@type": "ListItem", |
|
"position": 1, |
|
"name": "Crimson Knight Studios", |
|
"item": "https://www.crimsonknightstudios.com/" |
|
}<%- unless obj.nil? -%><%- obj.each_with_index do |path, index| -%> |
|
,{ |
|
"@type": "ListItem", |
|
"position": <%= index+2 -%>, |
|
"name": "<%= path[:name] -%>", |
|
"item": "https://www.crimsonknightstudios.com/<%= path[:slug] -%>" |
|
<%- if obj.length-1 == index || obj.nil? -%> |
|
}] |
|
<%- else -%> |
|
} |
|
<%- end -%> |
|
<%- end -%> |
|
<%- else -%> |
|
] |
|
<%- end -%> |
|
} |
|
</script> |