kcl-digital-humanities-garden/_plugins/empty_front_matter_note_injector.rb

22 lines
569 B
Ruby
Raw Normal View History

2021-03-11 03:33:55 +00:00
# frozen_string_literal: true
2021-04-11 17:04:24 +00:00
front_matter_date = DateTime.now.strftime('%Y-%m-%d')
2021-03-11 03:33:55 +00:00
EMPTY_FRONT_MATTER = <<~JEKYLL
---
2021-04-11 17:04:24 +00:00
date: #{front_matter_date}
2021-03-11 03:33:55 +00:00
---
JEKYLL
# Inject empty front matter in notes that don't have any
Jekyll::Hooks.register :site, :after_init do |site|
2021-04-01 02:50:13 +00:00
Dir.glob("#{site.collections['notes'].relative_directory}/**/*.md").each do |filename|
2021-03-11 03:33:55 +00:00
raw_note_content = File.read(filename)
unless raw_note_content.start_with?('---')
raw_note_content.prepend(EMPTY_FRONT_MATTER)
File.write(filename, raw_note_content)
end
end
end