Move galleries to collection, generate map and slideshow on build, stop using loopdir plugin, update templates accordingly
This commit is contained in:
27
_plugins/gallery.rb
Normal file
27
_plugins/gallery.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
module Jekyll
|
||||
class GalleryPage < Page
|
||||
def initialize(site, gallery, layout)
|
||||
@site = site
|
||||
@dir = gallery.url
|
||||
@name = layout + '.html'
|
||||
self.process(@name)
|
||||
self.read_yaml(File.join(site.source, '_layouts'), 'gallery-' + layout + '.html')
|
||||
self.data.merge!( gallery.data)
|
||||
self.data['gallery'] = gallery.url.split('/')[2]
|
||||
self.data['layout'] = 'gallery-' + layout
|
||||
end
|
||||
end
|
||||
|
||||
class GalleryPageGenerator < Generator
|
||||
def generate(site)
|
||||
site.collections['gallery'].docs.each do |gallery|
|
||||
if gallery.respond_to?('map')
|
||||
site.pages << GalleryPage.new(site, gallery, 'map')
|
||||
end
|
||||
if !gallery.respond_to?('slideshow')
|
||||
site.pages << GalleryPage.new(site, gallery, 'slideshow')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,100 +0,0 @@
|
||||
# inspired by
|
||||
# - https://gist.github.com/jgatjens/8925165
|
||||
# - http://simon.heimlicher.com/articles/2012/02/01/jekyll-directory-listing
|
||||
|
||||
module Jekyll
|
||||
class Loopdir < Liquid::Block
|
||||
include Liquid::StandardFilters
|
||||
Syntax = /(#{Liquid::QuotedFragment}+)?/
|
||||
|
||||
def initialize(tag_name, markup, tokens)
|
||||
@attributes = {}
|
||||
|
||||
@attributes['path'] = nil;
|
||||
@attributes['parse'] = 'true';
|
||||
@attributes['match'] = '*';
|
||||
@attributes['sort'] = 'path';
|
||||
|
||||
markup.scan(Liquid::TagAttributes) do | key, value |
|
||||
if 'path' == key
|
||||
# path can be dynamic to support includes
|
||||
@attributes['path'] = Liquid::Variable.new(value)
|
||||
else
|
||||
@attributes[key] = value.gsub /"(.*)"/, '\1'
|
||||
end
|
||||
end
|
||||
|
||||
if @attributes['path'].nil?
|
||||
raise SyntaxError.new("The `path` attribute is missing for `loopdir` tag.")
|
||||
end
|
||||
|
||||
if 'true' == @attributes['parse']
|
||||
@attributes['parse'] = true
|
||||
else
|
||||
@attributes['parse'] = false
|
||||
end
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def render(context)
|
||||
context.registers[:loopdir] ||= Hash.new(0)
|
||||
|
||||
items = []
|
||||
|
||||
path = @attributes['path'].render(context)
|
||||
|
||||
Dir.glob(File.join(path, @attributes['match'])).each do |pathname|
|
||||
if @attributes['parse']
|
||||
item = {}
|
||||
|
||||
content = File.read(pathname)
|
||||
|
||||
if content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
|
||||
content = $POSTMATCH
|
||||
|
||||
begin
|
||||
item = YAML.load($1)
|
||||
rescue => e
|
||||
puts "YAML Exception reading #{name}: #{e.message}"
|
||||
end
|
||||
end
|
||||
|
||||
item['content'] = content
|
||||
else
|
||||
context['item'] = pathname
|
||||
end
|
||||
|
||||
item['name'] = File.basename(pathname, @attributes['match'].sub('*', ''))
|
||||
item['fullname'] = pathname.gsub(/\.[^\.]+$/, '')
|
||||
item['path'] = pathname
|
||||
|
||||
items.push item
|
||||
end
|
||||
|
||||
sortby = @attributes['sort'].gsub(/^-/, '')
|
||||
|
||||
items.sort! do | x, y |
|
||||
x[sortby] <=> y[sortby]
|
||||
end
|
||||
|
||||
if sortby != @attributes['sort']
|
||||
items.reverse!
|
||||
end
|
||||
|
||||
context.stack do
|
||||
result = []
|
||||
|
||||
items.each do | item |
|
||||
context['item'] = item
|
||||
|
||||
result << render_all(@nodelist, context)
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Liquid::Template.register_tag('loopdir', Jekyll::Loopdir)
|
||||
Reference in New Issue
Block a user