Last active
November 24, 2017 17:26
-
-
Save sskylar/0b07f5f96c276c9913db60372246f8b2 to your computer and use it in GitHub Desktop.
Loop through Uploads in Siteleaf (or any files in a Jekyll collection)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
--- | |
{% assign collection = site.collections | where: 'label', 'uploads' | first %} | |
{% for file in collection.files %} | |
<li><img src="/uploads/{{ file.name }}"> | |
{% endfor %} |
Might be helpful: Jekyll gives us direct access to file extensions through file.extname
, so we can handle different file types. It's not unusual for my Uploads to end up containing other stuff like videos or PDFs.
I guess this is a sort of pull request:
---
---
{% assign collection = site.collections | where: 'label', 'uploads' | first %}
{% for file in collection.files %}
{% assign extension = file.extname | downcase %}
{% case extension %}
{% when ".jpg" or ".jpeg" or ".png" or ".gif" or ".svg" %}
<li><img src="/uploads/{{ file.name }}"></li>
{% when ".mp4" %}
<li><video controls src="/uploads/{{ file.name }}"></video></li>
{% else %}
<li><a href="/uploads/{{ file.name }}">{{ file.name }}</a></li>
{% endcase %}
{% endfor %}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your
_config.yml
should look something like this: