Class: JekyllThemeGuidesMbland::Breadcrumbs

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-theme-guides-mbland/breadcrumbs.rb

Class Method Summary collapse

Class Method Details

.create_breadcrumbs(site) ⇒ Object


13
14
15
16
17
# File 'lib/jekyll-theme-guides-mbland/breadcrumbs.rb', line 13

def self.create_breadcrumbs(site)
  (site.config['navigation'] || []).flat_map do |nav|
    Breadcrumbs.generate_breadcrumbs(nav, '/', [])
  end.to_h
end

.generate(site, docs) ⇒ Object


6
7
8
9
10
11
# File 'lib/jekyll-theme-guides-mbland/breadcrumbs.rb', line 6

def self.generate(site, docs)
  breadcrumbs = create_breadcrumbs(site)
  docs.each do |page|
    page.data['breadcrumbs'] = breadcrumbs[page.data[:working_url]]
  end
end

.generate_breadcrumbs(nav, parent_url, parents) ⇒ Object


19
20
21
22
23
24
25
26
# File 'lib/jekyll-theme-guides-mbland/breadcrumbs.rb', line 19

def self.generate_breadcrumbs(nav, parent_url, parents)
  url = parent_url + (nav['url'] || '')
  crumbs = parents + [{ 'url' => url, 'text' => nav['text'] }]
  child_crumbs = (nav['children'] || []).flat_map do |child|
    generate_breadcrumbs(child, url, crumbs)
  end
  [[url, crumbs]] + child_crumbs
end