2
votes

I am trying to use a loop over a Data File with Jekyll. The code I have is as follows:

<div class="row">
  <div class="12 columns">
    <ul class="clearing-thumbs" data-clearing>
      {% for photo in site.data.unusable_photos %}
        <li><a href="{{ photo.path }}" class="th"><img class="album-photo" data-caption="{{ photo.caption }}" src="{{ photo.thumb }}"></a></li>
      {% endfor %}
    </ul>
  </div>
</div>

However, it's getting hard to manually generate thumbnails for every photo I have. I found the Jekyll plugin thumbnail, but I don't know how to make it fit my needs.

The README shows this example: {% thumbnail /path/to/local/image.png 50x50< %}.

How can I use the {{ photo.path }} with the Jekyll plugin, so that I don't have to manually type filenames?

EDIT: Maybe I can edit the plugin so it can access the site variable?

1
Did you ever figure this out? I think putting photo.path would work...Kevin Chen
@KevinChen Unfortunately I did not, though I think I had a workaround. Let me check.tekknolagi
@KevinChen You know what, I don't know. Sorrytekknolagi
If anyone else finds this, I made a modified version of thumbnailer that looks up the path as a variable if it does not exist on disk. The magic happens in the call to look_up. github.com/kevin1/jekyll-thumbnailer/blob/master/thumbnail.rbKevin Chen
Actually I'm going to make that into an answerKevin Chen

1 Answers

1
votes

I made a modified version of thumbnailer that looks up what you put as path as a variable if it does not exist on disk. The magic happens in the call to look_up.

def look_up(context, name)
  lookup = context

  name.split(".").each do |value|
    lookup = lookup[value]
  end

  lookup
end

Then in render(context), call look_up:

source = look_up context, source unless File.readable?(source)

Full code: https://github.com/kevin1/jekyll-thumbnailer/blob/master/thumbnail.rb