Jekyll迭代自定义文件夹

Jekyll迭代自定义文件夹,jekyll,Jekyll,我正在使用Jekyll,有一个名为docs的自定义文件夹,其结构如下: 文件夹被组织为嵌套类别,但据我从中了解,如果我像这样使用collections\u dir,我只能有一个额外的级别: collections: js: output: true ruby: output: true collections_dir: docs 我想要的是能够遍历docs文件夹下的所有文件,以便创建搜索索引 我需要在这里更改站点。页面以获得在文档文件夹上迭代的内容,但我不知道如何才能

我正在使用Jekyll,有一个名为
docs
的自定义文件夹,其结构如下:

文件夹被组织为嵌套类别,但据我从中了解,如果我像这样使用
collections\u dir
,我只能有一个额外的级别:

collections:
  js:
    output: true
  ruby:
    output: true
collections_dir: docs
我想要的是能够遍历
docs
文件夹下的所有文件,以便创建搜索索引

我需要在这里更改
站点。页面
以获得在
文档
文件夹上迭代的内容,但我不知道如何才能做到这一点,以及我是否能够以一种不需要自己定义一个
.yml
文件的方式做到这一点

---
layout: null
---
[
  {% for page in site.pages %}
   {
     {% if page.title != nil %}
        "title"    : "{{ page.title | escape }}",
        "url"      : "{{ site.baseurl }}{{ page.url }}",
        "date"     : "{{ page.date }}"
     {% endif %}
   } {% unless forloop.last %},{% endunless %}
  {% endfor %}
]

您可以在Jekyll中迭代所有集合,然后访问每个集合中的文档/文件。查看和上的Jekyll文档

因此,您只需稍微调整一下现有内容,就可以得到如下结果:

---
layout: null
---
[
  {%- for collection in site.collections %}
  {%- for page in collection.docs -%}
   {
     {%- if page.title != nil %}
        "title"    : "{{ page.title | escape }}",
        "url"      : "{{ site.baseurl }}{{ page.url }}",
        "date"     : "{{ page.date }}"
     {% endif -%}
   }{% unless forloop.last %},{% endunless %}
  {%- endfor -%}
  {% endfor -%}
]

您可以在Jekyll中迭代所有集合,然后访问每个集合中的文档/文件。查看和上的Jekyll文档

因此,您只需稍微调整一下现有内容,就可以得到如下结果:

---
layout: null
---
[
  {%- for collection in site.collections %}
  {%- for page in collection.docs -%}
   {
     {%- if page.title != nil %}
        "title"    : "{{ page.title | escape }}",
        "url"      : "{{ site.baseurl }}{{ page.url }}",
        "date"     : "{{ page.date }}"
     {% endif -%}
   }{% unless forloop.last %},{% endunless %}
  {%- endfor -%}
  {% endfor -%}
]