class JekyllThemeGuidesMbland::NamespaceFlattener

Public Class Methods

check_for_collisions(flat_to_orig) click to toggle source
# File lib/jekyll-theme-guides-mbland/namespace_flattener.rb, line 28
def self.check_for_collisions(flat_to_orig)
  collisions = flat_to_orig.map do |flattened, orig|
    [flattened, orig] if orig.size != 1
  end.compact

  return if collisions.empty?

  messages = collisions.map { |flat, orig| "#{flat}: #{orig.join(', ')}" }
  raise StandardError, "collisions in flattened namespace between\n  " +
    messages.join("\n  ")
end
flat_url(url) click to toggle source
# File lib/jekyll-theme-guides-mbland/namespace_flattener.rb, line 24
def self.flat_url(url)
  url == '/' ? url : "/#{url.split('/')[1..-1].last}/"
end
flatten_page_urls(page, flat_to_orig) click to toggle source
# File lib/jekyll-theme-guides-mbland/namespace_flattener.rb, line 13
def self.flatten_page_urls(page, flat_to_orig)
  return if page.data['title'].nil?
  orig_url = page.data[:working_url]
  flattened_url = flat_url(orig_url)
  (flat_to_orig[flattened_url] ||= []) << orig_url
  page.data['permalink'] = flattened_url
  (page.data['breadcrumbs'] || []).each do |crumb|
    crumb['url'] = flat_url(crumb['url'])
  end
end
flatten_url_namespace(site, docs) click to toggle source
# File lib/jekyll-theme-guides-mbland/namespace_flattener.rb, line 3
def self.flatten_url_namespace(site, docs)
  flatten_urls(docs) if site.config['flat_namespace']
end
flatten_urls(docs) click to toggle source
# File lib/jekyll-theme-guides-mbland/namespace_flattener.rb, line 7
def self.flatten_urls(docs)
  flat_to_orig = {}
  docs.each { |page| flatten_page_urls(page, flat_to_orig) }
  check_for_collisions(flat_to_orig)
end