Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show the modification date of a file in Jekyll?

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?

like image 486
Robert Avatar asked Feb 20 '13 11:02

Robert


People also ask

What is the modified date on a file?

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.

Why is the date a file modified useful?

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.


2 Answers

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)

like image 143
Case Avatar answered Sep 26 '22 14:09

Case


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 }} 
like image 37
Juan A. Navarro Avatar answered Sep 26 '22 14:09

Juan A. Navarro