1

Imagine a directory specified in pages' front matter:

---
...
assets: "/assets/<project-name>"
...
---

How can one determine the number of files in the assets' sub-directories? For example:

{% assign img_dir = page.assets | append: "img/" %}

{% if <files-in-img_dir>.length > 1 %}
    // Render multiple images
{% else %}
    // Render single images
{% end if %}

As of right now I'm using something like below, but I would like to be able to optimize (imports, build, etc.) based on the number of assets to render.

{% for asset in site.static_files %}
    {% if asset.path contains img_dir %}
         // Render
    {% endif %}
{% endfor %}

Thanks.

conner.xyz
  • 6,273
  • 8
  • 39
  • 65

0 Answers0