Last active
February 18, 2020 01:45
-
-
Save yamitake/3659b9d87404ad975f8a881b05971e33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Author
yamitake
commented
Jan 28, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment