Module: Jekyll::Podcast::ValidateYAMLFrontmatter

Defined in:
lib/jekyll/podcast/validate_yaml_frontmatter.rb

Overview

Validate the frontmatter of each document using schemas in the _schemas directory

Class Method Summary collapse

Class Method Details



30
31
32
33
# File 'lib/jekyll/podcast/validate_yaml_frontmatter.rb', line 30

def print_document_validation_failed_message(document, errors)
  Jekyll.logger.info "Validation failed for #{document.path}:".yellow
  Jekyll.logger.info(errors.map { |x| "- #{x}" }.join("\n").yellow)
end


22
23
24
25
26
27
28
# File 'lib/jekyll/podcast/validate_yaml_frontmatter.rb', line 22

def print_validation_complete_message(error_count)
  if error_count.zero?
    Jekyll.logger.info 'YAML frontmatter validated successfully'.yellow
  else
    Jekyll.logger.info "YAML frontmatter validation failed with #{error_count} errors".yellow
  end
end

.validate_document(document) ⇒ Object



35
36
37
38
39
40
# File 'lib/jekyll/podcast/validate_yaml_frontmatter.rb', line 35

def validate_document(document)
  return [] unless File.exist? "_schemas/#{document.collection.label}.json"

  document_frontmatter = YAML.safe_load_file(document.path, permitted_classes: [Date]).to_json
  JSON::Validator.fully_validate("_schemas/#{document.collection.label}.json", document_frontmatter)
end

.validate_site(site) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/jekyll/podcast/validate_yaml_frontmatter.rb', line 42

def validate_site(site)
  Jekyll.logger.info 'Validating YAML frontmatter'.yellow
  error_count = 0
  site.documents.each do |document|
    result = validate_document(document)
    next if result.empty?

    error_count += result.length
    print_document_validation_failed_message(document, result)
  end
  print_validation_complete_message(error_count)
end