1
votes

I'm using Jekyll and have a custom folder called docs with this structure:

enter image description here

The folder is organized as nested categories, but from what I understand from this pull request I can only have one extra level if I use collections_dir like this:

collections:
  js:
    output: true
  ruby:
    output: true
collections_dir: docs

What I want is to be able to iterate through all the files under the docs folder in order to create a search index for simple-jekyll-search.

I need to change site.pages here for something that iterates on the docs folder but I don't know how I can do that and if I can do it in a way in which I don't need to define a .yml file listing all the files on the folder myself.

---
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 %}
]
1

1 Answers

0
votes

You can iterate over all of your collections in Jekyll and then access the documents/files within each of those collections. See the Jekyll docs on iterating over collections and accessing their documents.

So you'd just have to slightly tweak what you've got there to be something like:

---
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 -%}
]