2018-08-18 07:19:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-06 12:24:03 -04:00
|
|
|
module BreadcrumbsHelper
|
2017-07-07 16:50:34 -04:00
|
|
|
def add_to_breadcrumbs(text, link)
|
2017-07-06 12:24:03 -04:00
|
|
|
@breadcrumbs_extra_links ||= []
|
|
|
|
@breadcrumbs_extra_links.push({
|
|
|
|
text: text,
|
|
|
|
link: link
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
def breadcrumb_title_link
|
|
|
|
return @breadcrumb_link if @breadcrumb_link
|
|
|
|
|
2017-09-27 11:22:12 -04:00
|
|
|
request.path
|
2017-07-06 12:24:03 -04:00
|
|
|
end
|
2017-07-12 04:16:32 -04:00
|
|
|
|
|
|
|
def breadcrumb_title(title)
|
|
|
|
return if defined?(@breadcrumb_title)
|
|
|
|
|
|
|
|
@breadcrumb_title = title
|
|
|
|
end
|
2017-08-16 05:35:59 -04:00
|
|
|
|
|
|
|
def breadcrumb_list_item(link)
|
|
|
|
content_tag "li" do
|
2022-06-13 05:09:24 -04:00
|
|
|
link + sprite_icon("chevron-lg-right", size: 8, css_class: "breadcrumbs-list-angle")
|
2017-08-16 05:35:59 -04:00
|
|
|
end
|
|
|
|
end
|
2017-08-16 08:13:34 -04:00
|
|
|
|
2021-11-02 08:12:25 -04:00
|
|
|
def add_to_breadcrumb_collapsed_links(link, location: :before)
|
|
|
|
@breadcrumb_collapsed_links ||= {}
|
|
|
|
@breadcrumb_collapsed_links[location] ||= []
|
|
|
|
@breadcrumb_collapsed_links[location] << link
|
2017-08-16 08:13:34 -04:00
|
|
|
end
|
2020-11-11 19:09:44 -05:00
|
|
|
|
|
|
|
def push_to_schema_breadcrumb(text, link)
|
|
|
|
list_item = schema_list_item(text, link, schema_breadcrumb_list.size + 1)
|
|
|
|
|
|
|
|
schema_breadcrumb_list.push(list_item)
|
|
|
|
end
|
|
|
|
|
|
|
|
def schema_breadcrumb_json
|
|
|
|
{
|
|
|
|
'@context': 'https://schema.org',
|
|
|
|
'@type': 'BreadcrumbList',
|
|
|
|
'itemListElement': build_item_list_elements
|
|
|
|
}.to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def schema_breadcrumb_list
|
|
|
|
@schema_breadcrumb_list ||= []
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
'@type' => 'ListItem',
|
|
|
|
'position' => position,
|
|
|
|
'name' => text,
|
2020-11-13 10:09:24 -05:00
|
|
|
'item' => ensure_absolute_link(link)
|
2020-11-11 19:09:44 -05:00
|
|
|
}
|
|
|
|
end
|
2020-11-13 10:09:24 -05:00
|
|
|
|
|
|
|
def ensure_absolute_link(link)
|
|
|
|
url = URI.parse(link)
|
|
|
|
url.absolute? ? link : URI.join(request.base_url, link).to_s
|
|
|
|
rescue URI::InvalidURIError
|
|
|
|
"#{request.base_url}#{request.path}"
|
|
|
|
end
|
2017-07-06 12:24:03 -04:00
|
|
|
end
|