chirpy-starter/_plugins/posts-lastmod-hook.rb
2024-08-02 06:58:38 +03:00

15 lines
335 B
Ruby

#!/usr/bin/env ruby
#
# Check for changed posts
Jekyll::Hooks.register :posts, :post_init do |post|
commit_num = `git rev-list --count HEAD "#{ post.path }"`.strip
if commit_num.to_i > 1
lastmod_date = `git log -1 --pretty="%ad" --date=iso "#{ post.path }"`.strip
post.data['last_modified_at'] = lastmod_date
end
end