annabunches.net/_plugins/category_page.rb

38 lines
869 B
Ruby

class CategoryPage < Jekyll::Page
def initialize(site, base, category)
@site = site
@base = base
@dir = category
@name = 'index.html'
self.process(@name)
self.read_yaml(File.join(base, '_layouts'), 'category_index.html')
self.data['category'] = category
config = site.config['category_metadata'][category]
if config.nil?
self.data['title'] = category.capitalize
self.data['description'] = ''
else
self.data['title'] = config['title']
self.data['description'] = config['description']
end
end
end
class CategoryPageGenerator < Jekyll::Generator
safe true
def generate(site)
if !site.layouts.key? 'category_index'
return
end
site.config['category_metadata'].each_key do |category|
site.pages << CategoryPage.new(site, site.source, category)
end
end
end