forked from callmeed/jekyll-image-set
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_set.rb
50 lines (37 loc) · 1.32 KB
/
image_set.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# ImageSet Liquid Plugin
# by Erik Dungan
# erik.dungan@gmail.com / @callmeed
#
require 'mini_magick'
class ImageSet < Liquid::Tag
@path = nil
@class = nil
def initialize(tag_name, text, tokens)
super
@path = text.split(/\s+/)[0].strip
@class = 'image'
end
def render(context)
full_path = File.join(context.registers[:site].config['source'], "_" + @path, "*.{jpg,jpeg,JPG,JPEG,png,PNG}")
source = "<div class='image-set'>\n"
files = Dir.glob(full_path).uniq.sort
Dir.glob(files).each do |image|
check = image.end_with? ".thumb.jpg"
if check == false
file = Pathname.new(image).basename.to_s
src = File.join('/', @path, file)
src_thumb = File.join('/', @path, file + ".thumb.jpg")
source += "<a class='image-item'>\n"
source += "<img src='#{src}' alt='gallery item' width='100%' class='responsive-img materialboxed lazyload'>\n" +
"<img src='#{src_thumb}' alt='gallery item' width='100%' class='responsive-img materialboxed lazyload'>\n"
source += "</a>\n"
img = MiniMagick::Image.open(image)
img.resize "30%x30%"
img.write(image + ".thumb.jpg")
end
end
source += "</div>\n"
source
end
Liquid::Template.register_tag 'image_set', self
end