7
1
mirror of https://gitlab.com/ansol/web-ansol.org.git synced 2024-11-10 00:30:36 +00:00
web-ansol.org/checkdates.rb

37 lines
1.2 KiB
Ruby
Raw Normal View History

2024-01-01 16:15:35 +00:00
#!/usr/bin/env ruby
require 'yaml'
require 'date'
class YAMLFrontMatter
PATTERN = /\A(---\r?\n(.*?)\n?^---\s*$\n?)/m.freeze
class << self
def extract(content)
if content =~ PATTERN
[YAML.load(Regexp.last_match(2), permitted_classes: [Symbol, Date, Time]), content.sub(Regexp.last_match(1), "")]
else
[{}, content]
end
end
end
end
Dir["content/eventos/*/index.md"].each do |filename|
metadata, _ = YAMLFrontMatter.extract(File.read(filename))
raise "#{filename}: wrong layout: #{metadata["layout"]}" unless metadata["layout"] == "evento"
raise "#{filename}: no title" unless metadata.keys.include?("title")
raise "#{filename}: no metadata" unless metadata.keys.include?("metadata")
raise "#{filename}: no event location" unless metadata.dig("metadata", "event", "location")
start = metadata.dig("metadata", "event", "date", "start")
finish = metadata.dig("metadata", "event", "date", "finish")
raise "#{filename}: no event start date" unless start
raise "#{filename}: no event finish date" unless finish
raise "#{filename}: time paradox: #{start} - #{finish}" unless start.to_time <= finish.to_time
end