有没有办法动态获取 Jekyll 集合中的文档列表

Is there a way to dynamically get a list of documents in a Jekyll collection

我对 Jekyll 还很陌生,目前正在尝试建立一个网站来容纳一堆包含课程培训的页面 material。我正在尝试使用 Jeykll 集合来执行此操作并具有如下站点结构:

/
|
|_ "_course001"
    |
    |_ subdirs/subdocs
|_ "_course002"
    |
    |_ subdirs/subdocs

在为每门课程呈现内容时(设置为集合)我希望导航栏仅显示当前 course/collection 中的其他文档(即不显示在其他课程中)。

使用类似这样的方法有效:

{% for each coursedoc in site.course001 %} 
   [Create anchors and text]
{% endfor %}

但是我希望在站点构建期间通过动态分配而不是硬编码来获得集合名称。我试过这样做:

{% for each coursedoc in {{ page.collection | prepend: "site." }} %} 
   [Create anchors and text]
{% endfor %}

但这行不通,我猜是因为{{ page.collection | prepend: "site." }} returns一个字符串。

有人对我如何做到这一点有什么建议吗?

我想我刚刚回答了我自己的问题:

{% assign collection =  site.collections | where: "label", page.collection | first %}

{% for node in collection.docs %}
[Create anchors and text]
{% endfor %}