Created
April 13, 2011 09:19
-
-
Save baldowl/917251 to your computer and use it in GitHub Desktop.
Rough gallery plugin for Jekyll
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
# Basic: add a `gallery` attribute to the YAML header of any page with value | |
# being the extension of your images. Every image with that extension stored | |
# inside the page's directory (and every one of its subdirectories) will be | |
# added to the `gallery_items` attribute of that same page (alphabetically | |
# sorted). | |
module Jekyll | |
class Gallery < Generator | |
safe true | |
def generate site | |
site.pages.each do |page| | |
gallery(site, page) if page.data['gallery'] | |
end | |
end | |
def gallery site, page | |
base = page.instance_variable_get :@dir | |
search = File.join '**', "*.#{page.data['gallery']}" | |
images = Dir.chdir(base[1..-1] || '.') do | |
Dir.glob(search).sort.map {|image| File.join base, image} | |
end | |
page.data = page.data.deep_merge 'gallery_items' => images | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment