Created
August 14, 2010 21:41
-
-
Save josegonzalez/524748 to your computer and use it in GitHub Desktop.
Category 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
module Jekyll | |
class CategoryIndex < Page | |
def initialize(site, base, dir, category) | |
@site = site | |
@base = base | |
@dir = dir | |
@name = 'index.html' | |
self.process(@name) | |
self.read_yaml(File.join(base, '_layouts'), 'category_index.html') | |
self.data['category'] = category | |
category_title_prefix = site.config['category_title_prefix'] || 'Category: ' | |
self.data['title'] = "#{category_title_prefix}#{category}" | |
end | |
end | |
class CategoryGenerator < Generator | |
safe true | |
def generate(site) | |
if site.layouts.key? 'category_index' | |
dir = site.config['category_dir'] || 'categories' | |
site.categories.keys.each do |category| | |
write_category_index(site, File.join(dir, category), category) | |
end | |
end | |
end | |
def write_category_index(site, dir, category) | |
index = CategoryIndex.new(site, site.source, dir, category) | |
index.render(site.layouts, site.site_payload) | |
index.write(site.dest) | |
end | |
end | |
end |
Add it to the _plugins directory of your Jekyll project. Should run automatically on build.
At the moment I'm trying to get your script work with Jekyll 3.0.1. But when I build the page using "jekyll build" the pages are only temporarly created and get removed after around 2 seconds. Does this script only work with older jekyll versions?
@xylo See the CategoryPageGenerator example on the Jekyll site: http://jekyllrb.com/docs/plugins/#generators
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do you use this?