Skip to content

Instantly share code, notes, and snippets.

@yamitake
Last active February 18, 2020 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yamitake/3659b9d87404ad975f8a881b05971e33 to your computer and use it in GitHub Desktop.
Save yamitake/3659b9d87404ad975f8a881b05971e33 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
module Gretel
module ViewHelpers
delegate :breadcrumbs_json_ld, to: :gretel_renderer
end
class Renderer
# rubocop:disable Rails/OutputSafety
def breadcrumbs_json_ld
{
"@context": 'http://schema.org/',
"@type": 'BreadcrumbList',
"itemListElement": links.map.with_index do |link, i|
{
'@type': 'ListItem',
'position': i + 1,
'item': {
'@id': "#{root_url.chop}#{link}",
'name': link.text
}
}
end
}.to_json.html_safe
end
# rubocop:enable Rails/OutputSafety
end
end
@yamitake
Copy link
Author

.breadcrumbs
          == breadcrumbs style: :bootstrap
          = tag.script(breadcrumbs_json_ld, type: 'application/ld+json')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment