tekknolagi
tekknolagi

Reputation: 11022

Jekyll thumbnail plugin with Liquid tag

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?

Upvotes: 2

Views: 1292

Answers (1)

Kevin Chen
Kevin Chen

Reputation: 1026

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

Upvotes: 1

Related Questions