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
51
52
53
54
55
56
57
58
59
|
# File 'lib/jekyll-auto-image-include.rb', line 13
def render(context)
site = context.registers[:site]
base_dir = site.config['source']
recursion = '/'
pattern = '*.{jpg,jpeg,png,gif,bmp,tif,tiff,svg}'
page = context.environments.first["page"]
if @path == nil || @path == ""
dir = page["dir"]
else
dir = @path.strip
end
if site.config['auto_image_include']
config = site.config['auto_image_include']
if config['pattern']
pattern = config['pattern']
end
if config['recursive']
recursion = '/**/'
end
end
output = ''
folder = File.join(base_dir, dir, recursion + pattern)
files = Dir.glob(folder, File::FNM_CASEFOLD).sort
files.each do |image_fullpath|
image_path = image_fullpath.sub(base_dir, '')
image_name = File.basename(image_fullpath)
output += "\n<a href=\"#{image_path}\"><img src=\"#{image_path}\" alt=\"#{image_name}\"></a>"
end
output
end
|