Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jekyll 上次修改日期钩子到集合_Jekyll - Fatal编程技术网

Jekyll 上次修改日期钩子到集合

Jekyll 上次修改日期钩子到集合,jekyll,Jekyll,我正在尝试应用于自定义集合: 钩住 Jekyll::Hooks.register :docs, :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'] = modifi

我正在尝试应用于自定义集合:

钩住

Jekyll::Hooks.register :docs, :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
收藏

collections:
  docs:
    output: true
但是现在没有指定上次修改日期

我发现使用集合名称应该是可行的

我试图按日期排序并列出它们,但现在字段是空的。我在文档中的所有字段都是在设置钩子之前创建的,所以我可能需要做些什么才能让它工作

有什么想法吗? 钩子什么时候开?(专门针对预先存在的文件)
我应该如何设置它以使用集合?

试试这个,当您在本地构建或服务jekyll站点时,它应该在控制台中输出一些信息。这有助于调试

_插件/hook-docs-pre-render.rb
请注意,钩子在github页面上不起作用。

我在控制台上看不到任何东西,所以我猜有些东西不起作用。谢谢你的github页面说明,我正在其他地方托管它。有存储库url吗?这有助于调试。
Jekyll::Hooks.register :docs, :pre_render do |post|

  # debug
  puts "Firing :docs, :pre_render from : " + File.basename(__FILE__) + " for : " + post.relative_path

  # get the current post last modified time
  modification_time = File.mtime( post.path )

  # debug
  puts "modification_time = " + modification_time.strftime('%A, %B %dth %Y at %l:%M%p')

  # inject modification_time in post's datas.
  post.data['last-modified-date'] = modification_time

end