Class: RageRender::ChapterFromDirectorySetter

Inherits:
Jekyll::Generator
  • Object
show all
Defined in:
lib/ragerender/jekyll/comics.rb

Overview

If the image for this comic was inside a subdirectory, set that subdirectory name to be the chapter slug for this comic, if one is not already set.

Instance Method Summary collapse

Instance Method Details

#generate(site) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/ragerender/jekyll/comics.rb', line 82

def generate site
  site.collections['comics'].docs.each do |comic|
    components = Pathname.new(comic.data['image']).descend.reduce([]) {|acc, path| acc << path.basename }
    chapter_slug = components.drop_while {|path| path.root? || path.to_s == 'images' }[...-1].first
    comic.data['chapter'] ||= chapter_slug.to_s unless chapter_slug.nil?
  end
end