From cfff3b3737c94dd3d942150bb16e66784178e509 Mon Sep 17 00:00:00 2001 From: Maxime Vaillancourt Date: Sun, 22 Nov 2020 13:01:29 -0500 Subject: [PATCH] Ensure all notes have front matter --- _plugins/empty_front_matter_note_injector.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 _plugins/empty_front_matter_note_injector.rb diff --git a/_plugins/empty_front_matter_note_injector.rb b/_plugins/empty_front_matter_note_injector.rb new file mode 100644 index 0000000..c4979c9 --- /dev/null +++ b/_plugins/empty_front_matter_note_injector.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +EMPTY_FRONT_MATTER = <<~JEKYLL + --- + --- + +JEKYLL + +# Inject empty front matter in notes that don't have any +Jekyll::Hooks.register :site, :after_init do |site| + Dir.glob(site.collections['notes'].relative_directory + '/**/*.md').each do |filename| + raw_note_content = File.read(filename) + raw_note_content.prepend(EMPTY_FRONT_MATTER) unless raw_note_content.start_with?('---') + File.write(filename, raw_note_content) + end +end