From 2add4aeede67f48e0369dbe490c32236b192d99c Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Mon, 23 Jan 2023 13:41:00 +0100 Subject: [PATCH] Add last modified to posts and repos --- _plugins/hook-add-last-modified-date.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 _plugins/hook-add-last-modified-date.rb diff --git a/_plugins/hook-add-last-modified-date.rb b/_plugins/hook-add-last-modified-date.rb new file mode 100644 index 00000000..834d39f3 --- /dev/null +++ b/_plugins/hook-add-last-modified-date.rb @@ -0,0 +1,22 @@ +# see https://stackoverflow.com/a/36769049/17860466 + +Jekyll::Hooks.register :posts, :pre_render do |post| + + # get the current post last modified time + modification_time = File.mtime( post.path ) + + # inject modification_time in post's datas. + post.data['last-modified-date'] = modification_time + +end + + +Jekyll::Hooks.register :repo, :pre_render do |repo| + + # get the current post last modified time + modification_time = File.mtime( repo.path ) + + # inject modification_time in post's datas. + repo.data['last-modified-date'] = modification_time + +end \ No newline at end of file