在Jekyll中按日期筛选液体过滤器的解决方法如下:
date_filter.rb
的文件,并将以下代码粘贴到文件中:require 'date'
module Jekyll
module DateFilter
def filter_by_date(collection, date)
collection.select { |item| item.date.to_date == Date.parse(date) }
end
end
end
Liquid::Template.register_filter(Jekyll::DateFilter)
_config.yml
中添加以下内容:gems:
- jekyll-date
filter_by_date
过滤器。例如,假设你有一个名为posts
的集合,你可以按日期筛选它:{% assign filtered_posts = site.posts | filter_by_date: '2021-01-01' %}
这将返回一个包含所有发布日期为2021年1月1日的文章的集合。
请确保你的Jekyll版本与jekyll-date
插件兼容。你可以在Jekyll的官方网站上查找有关插件的更多信息,并检查插件是否与你当前使用的Jekyll版本兼容。
上一篇:按日期筛选现有查询