如果您使用自己的页面构建,jekyll build
您可以简单地创建一个名为_plugins/page_filters.rb
以下内容的文件:
module Jekyll
module PageFilters
def children_of(all_pages, parent)
all_pages.select { |p| child_of?(p, parent) }
end
private
def child_of?(child, parent)
parent_path = parent["path"]
child_path = child.path
# Exclude 'index.md' from becoming a child of itself
return false if parent_path == child_path
# Remove 'index.md' from the parent path
parent_path = parent_path.split("index.md", 2).first
child_path.start_with? parent_path
end
end
end
Liquid::Template.register_filter(Jekyll::PageFilters)
然后像这样调用children_of
过滤器:
{% assign children = site.pages | children_of: page %}
<ul>
{% for child in children %}
<li><a href="{{ child.url }}">{{ child.title }}</a></li>
{% endfor %}
</ul>