Last active
August 29, 2015 14:05
-
-
Save jgarber623/b5c331a805e959b10fc7 to your computer and use it in GitHub Desktop.
Generate tag pages in Jekyll at /tags/tag_name_with_underscores/index.html.
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 TagPage < Page | |
def initialize(site, base, dir, data = {}) | |
@site = site | |
@base = base | |
@dir = dir | |
@name = 'index.html' | |
data['layout'] = 'posts-list' | |
data['title'] = "Posts tagged “#{data['tag']}”" | |
self.data = data | |
process(@name) | |
end | |
def read_yaml(*) | |
# Do nothing | |
end | |
end | |
class TagPageGenerator < Generator | |
safe true | |
def generate(site) | |
site.tags.each do |tag, posts| | |
site.pages << TagPage.new(site, site.source, File.join('tags', tag.downcase.tr(' ', '_')), {'tag' => tag, 'posts' => posts}) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment