Skip to content

Instantly share code, notes, and snippets.

@letrastudio
Created March 13, 2018 11:35
Show Gist options
  • Save letrastudio/4e678722e0b7400655ecd15fa33d6e0d to your computer and use it in GitHub Desktop.
Save letrastudio/4e678722e0b7400655ecd15fa33d6e0d to your computer and use it in GitHub Desktop.
Loop though media files in a Jekyll collection and display them in a list
---
---
<ul>
{% 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 %}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment