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
- .print_document_validation_failed_message(document, errors) ⇒ Object
- .print_validation_complete_message(error_count) ⇒ Object
- .validate_document(document) ⇒ Object
- .validate_site(site) ⇒ Object
Class Method Details
.print_document_validation_failed_message(document, errors) ⇒ Object
30 31 32 33 |
# File 'lib/jekyll/podcast/validate_yaml_frontmatter.rb', line 30 def (document, errors) Jekyll.logger.info "Validation failed for #{document.path}:".yellow Jekyll.logger.info(errors.map { |x| "- #{x}" }.join("\n").yellow) end |
.print_validation_complete_message(error_count) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/jekyll/podcast/validate_yaml_frontmatter.rb', line 22 def (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 (document, result) end (error_count) end |