3 class CategoryPage < Page
4 def initialize(site, base, dir, name, category, layout)
11 self.read_yaml(File.join(base, '_layouts'), layout)
12 self.data['category'] = category # this tells the site template to add a link to the RSS feed
14 category_title_prefix = site.config['blog']['title'] + ": "
15 self.data['title'] = "#{category_title_prefix}#{category.capitalize}"
19 class CategoryPageGenerator < Generator
23 return if site.config['blog'].nil?
24 dir = site.config['blog']['category_dir'] || 'categories'
25 if site.layouts.key? 'category_index'
26 site.categories.each_key do |category|
27 site.pages << CategoryPage.new(site, site.source, dir, "#{category}.html", category, 'category_index.html')
30 if site.layouts.key? 'category_feed'
31 site.categories.each_key do |category|
32 site.pages << CategoryPage.new(site, site.source, dir, "#{category}.xml", category, 'category_feed.html')
38 # Adds some extra filters used during the category creation process.
41 # Outputs a list of categories as comma-separated <a> links. This is used
42 # to output the category list for each post on a category page.
44 # +categories+ is the list of categories to format.
47 def category_links(categories)
48 cat_base_dir = File.join(@context.registers[:site].config['baseurl'], @context.registers[:site].config['blog']['category_dir'])
49 categories = categories.sort!.map do |category|
50 category_url = File.join(cat_base_dir, "#{category}.html")
51 "<a class='category' href='#{category_url}'>#{category.capitalize}</a>"
54 case categories.length
66 Liquid::Template.register_filter(Jekyll::CategoryFilter)