I know that I can specify a variable date
in the YAML frontmatter of a file and access its value with {{ page.date }}
. This is cumbersome since one easily forgets to change the date when a file is updated. So how can I access a file's modification date?
The modified date of a file or folder represents the last time that file or folder was updated. If you're having trouble with the modified dates of your files or folders, check out these frequently-asked questions.
With respect to files created by a computer user, however, the last modified date will generally indicate the last date and time that a file was saved. The last access date stamp refers to just about any activity that a user or even the computer system itself might do to a file.
This is a relatively new plugin that does what you're looking for:
https://github.com/gjtorikian/jekyll-last-modified-at
(found it while searching Google for alternatives to the other answers in this thread)
From Jekyll 1.x there is a page.path
that gives you the filename of the post or page being currently processed. Add the following filter (place e.g. in _plugins/myfilters.rb
) to get the modification time of a given filename:
module Jekyll module MyFilters def file_date(input) File.mtime(input) end end end Liquid::Template.register_filter(Jekyll::MyFilters)
So now you can render the date on your posts and pages, e.g., as
{{ page.path | file_date | date_to_string }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With