Created
March 22, 2012 02:04
-
-
Save erjjones/2155135 to your computer and use it in GitHub Desktop.
Jekyll-Tags
This file contains hidden or 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 TagIndex < Page | |
| def initialize(site, base, dir, tag) | |
| @site = site | |
| @base = base | |
| @dir = dir | |
| @name = 'index.html' | |
| self.process(@name) | |
| self.read_yaml(File.join(base, '_layouts'), 'tag_index.html') | |
| self.data['tag'] = tag | |
| self.data['title'] = "Posts Tagged “"+tag+"”" | |
| end | |
| end | |
| class TagGenerator < Generator | |
| safe true | |
| def generate(site) | |
| if site.layouts.key? 'tag_index' | |
| dir = 'tags' | |
| site.tags.keys.each do |tag| | |
| write_tag_index(site, File.join(dir, tag), tag) | |
| end | |
| end | |
| end | |
| def write_tag_index(site, dir, tag) | |
| index = TagIndex.new(site, site.source, dir, tag) | |
| index.render(site.layouts, site.site_payload) | |
| index.write(site.dest) | |
| site.pages << index | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment