Module: JekyllThemeGuidesMbland::FrontMatter

Defined in:
lib/jekyll-theme-guides-mbland/navigation.rb

Constant Summary collapse

EXTNAMES =
%w[.md .html].freeze

Class Method Summary collapse

Class Method Details

.load(basedir) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/jekyll-theme-guides-mbland/navigation.rb', line 10

def self.load(basedir)
  # init_file_to_front_matter_map is initializing the map with a nil value
  # for every file that _should_ contain front matter as far as the
  # navigation menu is concerned. Any nil values that remain after merging
  # with the site_file_to_front_matter map will result in a validation
  # error.
  init_file_to_front_matter_map(basedir)
    .merge(site_file_to_front_matter(init_site(basedir)))
end

.validate(front_matter) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/jekyll-theme-guides-mbland/navigation.rb', line 31

def self.validate(front_matter)
  front_matter.map do |file, data|
    next [file, ['no front matter defined']] if data.nil?
    errors = missing_property_errors(data) + permalink_errors(data)
    [file, errors] unless errors.empty?
  end.compact.to_h
end

.validate_with_message_upon_error(front_matter) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/jekyll-theme-guides-mbland/navigation.rb', line 20

def self.validate_with_message_upon_error(front_matter)
  files_with_errors = validate front_matter
  return if files_with_errors.empty?
  message = ['The following files have errors in their front matter:']
  files_with_errors.each do |file, errors|
    message << "  #{file}:"
    message.concat(errors.map { |error| "    #{error}" })
  end
  message.join "\n" unless message.size == 1
end