I would like to automatically insert a last updated timestamp (Not the date
variable for the page) for each post at Jekyll build time, how to achieve that? I th
The only collection that has a modified_time
is site.static_files
. Not so useful in our case.
One way to get the last-modified-date
for posts in your Jekyll site is to use a hook (documentation).
_plugins/hook-add-last-modified-date.rb
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
It's now available in your posts as : {{ page.last-modified-date }}
.
And you can format this date with the a date filter like {{ page.last-modified-date | date: '%B %d, %Y' }}
. See the Alan W. Smith excellent article on date Jekill Liquid date formating topic.
Important notice : hooks are not working on Github pages.