Jekyll - Get all folders in a directory and generate pages

Viewed 1023

I have a folder structure like so:

/gallery/images/category1/
/gallery/images/category2/
/gallery/images/category3/
/gallery/images/category4/
/gallery/images/category5/

and so on..

Inside each of these folders, there are a bunch of images. However, these category folders are always changing, the names as well.

My goal is to have jekyll auto generate a seperate page for each on of these categories. Then in this page, cycle through each image in that folder and display it on the page.

What I need help on:

  • How do I look in the /gallery/images folder and grab all the folders
  • Once I know all the folders, how do you generate a page such as /gallery/[FOLDER_NAME].html for each one of them

Once I am able to do that, I know I can have the follow as the content of the page and be fine.

{% for image in site.static_files %}
    {% if image.path contains 'gallery/{{ FOLDER_NAME }}' %}
        <img src="{{ site.baseurl }}{{ image.path }}" />
    {% endif %}
{% endfor %}

Any help or guidance would be greatly appreciated.

1 Answers
Related