如何在构建时在Jekyll页面中插入最后更新的时间戳?

Lor*_*lor 10 jekyll

我想date在Jekyll构建时为每个帖子自动插入最后更新的时间戳(不是页面的变量),如何实现?我想我必须声明一个变量,但我不知道如何将值赋给该变量.

例如,有时我更新旧帖子,除了显示发布日期之外,我还想显示上次更新日期.

我试过{{Time.now}}但似乎不起作用.

Dav*_*uel 16

唯一拥有的集合modified_timesite.static_files.在我们的案例中没那么有用.

last-modified-date在Jekyll网站上获取帖子的一种方法是使用钩子(文档).

_plugins /钩附加最后一次修改,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
Run Code Online (Sandbox Code Playgroud)

它现在可以在您的文章如下:{{ page.last-modified-date }}.您可以使用日期过滤器格式化此日期{{ page.last-modified-date | date: '%B %d, %Y' }}.请参阅关于约会Jekill Liquid日期格式主题Alan W. Smith优秀文章.

重要提示:钩子无法在Github页面上运行.