Skip to content

Instantly share code, notes, and snippets.

@jgarber623
Last active August 29, 2015 14:05
Show Gist options
  • Save jgarber623/b5c331a805e959b10fc7 to your computer and use it in GitHub Desktop.
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.
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