Sha256: 85872677ff11fa78a71b6c38003541e4fd1690082cfde3e2eb7ceaa5558cfb75
Contents?: true
Size: 810 Bytes
Versions: 8
Compression:
Stored size: 810 Bytes
Contents
require 'jekyll' require 'safe_yaml' module JekyllThemeGuidesMbland class Breadcrumbs def self.generate(site, docs) breadcrumbs = create_breadcrumbs(site) docs.each do |page| page.data['breadcrumbs'] = breadcrumbs[page.data[:working_url]] end end def self.create_breadcrumbs(site) (site.config['navigation'] || []).flat_map do |nav| Breadcrumbs.generate_breadcrumbs(nav, '/', []) end.to_h end 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 end end
Version data entries
8 entries across 8 versions & 1 rubygems