Created
April 3, 2014 12:14
-
-
Save vegetableman/9953242 to your computer and use it in GitHub Desktop.
jekyll generator to iterate through image dir and concatenate files under subdirectories including a 'main' subdirectory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Jekyll | |
class ImageListGenerator < Generator | |
def generate(site) | |
imagemap = {} | |
imagearr = [] | |
dir = "" | |
#create a dir and image map | |
Dir.glob(File.join(site.source,'_images/**/*')).each {|f| | |
if File.directory?(f) then | |
puts File.basename(f) | |
if File.basename(f) == 'main' then | |
imagemap[dir] = File.basename(f) | |
else | |
dir = File.basename(f) | |
imagemap[dir] = nil | |
imagearr = [] | |
end | |
else | |
if File.extname(f) == ".jpg" then | |
if imagemap[dir] == 'main' then | |
imagemap[dir] = imagearr.push('main/'+File.basename(f)) | |
else | |
imagemap[dir] = imagearr.push(File.basename(f)) | |
end | |
end | |
end | |
} | |
#remove keys for nil values | |
imagemap.delete_if {|k,v| v.nil?} | |
site.config['imagemap'] = imagemap | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment