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