Class: Jekyll::FlickrPageGenerator

Inherits:
Generator
  • Object
show all
Defined in:
lib/badpixxel-jekyll-flickr.rb

Instance Method Summary collapse

Instance Method Details

#generate(site) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/badpixxel-jekyll-flickr.rb', line 75

def generate(site)
    Jekyll::flickr_setup(site)
    cache_dir = site.config['flickr']['cache_dir']
    
    file_photosets = Dir.glob(File.join(cache_dir, '*.yml'))
    file_photosets.each_with_index do |file_photoset, pos|
        photoset = Photoset.new(site, file_photoset)
        if site.config['flickr']['generate_photosets'].include? photoset.title
            # generate photo pages if requested
            if site.config['flickr']['generate_posts']
                file_photos = Dir.glob(File.join(photoset.cache_dir, '*.yml'))
                file_photos.each do |file_photo, pos|
                    photo = Photo.new(site, photoset, file_photo, pos)
                    page_photo = PhotoPost.new(site, site.source, '', photo)

                    # posts need to be in a _posts directory, but this means Jekyll has already
                    # read in photo posts from any previous run... so for each photo, update
                    # its associated post if it already exists, otherwise create a new post
                    site.posts.each_with_index do |post, pos|
                        if post.data['slug'] == photo.slug
                            site.posts.delete_at(pos)
                        end
                    end
                    site.posts << page_photo
                end
            end
        end
    end
    
    # re-sort posts by date
    site.posts.sort! {|left, right| left.date <=> right.date}
end