Tenta meter checks às datas no CI

This commit is contained in:
Hugo Peixoto 2024-01-01 16:15:35 +00:00
parent 8a23c8f0f1
commit ea4ed078ed
4 changed files with 39 additions and 2 deletions

View File

@ -2,6 +2,7 @@ image: klakegg/hugo:0.88.0-ext-ci # recommended image by Hugo: https://gohugo.io
test:
script:
- ./checkdates.rb
- hugo
except:
- master

36
checkdates.rb Executable file
View File

@ -0,0 +1,36 @@
#!/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

View File

@ -1,5 +1,5 @@
---
categories: []
layout: evento
metadata:
event:
location: Online

View File

@ -3,7 +3,7 @@ layout: evento
title: Devops na Praia #2
metadata:
event:
location:
location: Wunderman Thompson Commerce - Edifício Transparente, Porto
site:
url: https://www.eventbrite.pt/e/bilhetes-devops-na-praia-2-720753933417?aff=oddtdtcreator
date: