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
14 category_title_prefix = site.config['blog']['category_title_prefix'] || 'Category: '
15 self.data['title'] = "#{category_title_prefix}#{category.capitalize}"
19 class CategoryPageGenerator < Generator
23 dir = site.config['blog']['category_dir'] || 'categories'
24 if site.layouts.key? 'category_index'
25 site.categories.each_key do |category|
26 site.pages << CategoryPage.new(site, site.source, dir, "#{category}.html", category, 'category_index.html')
29 if site.layouts.key? 'category_feed'
30 site.categories.each_key do |category|
31 site.pages << CategoryPage.new(site, site.source, dir, "#{category}.xml", category, 'category_feed.html')
37 # Adds some extra filters used during the category creation process.
40 # Outputs a list of categories as comma-separated <a> links. This is used
41 # to output the category list for each post on a category page.
43 # +categories+ is the list of categories to format.
46 def category_links(categories)
47 base_dir = @context.registers[:site].config['blog']['category_dir']
48 categories = categories.sort!.map do |category|
49 category_url = File.join(base_dir, "#{category}.html")
50 # Make sure the category directory begins with a slash.
51 category_dir = "/#{category_dir}" unless category_dir =~ /^\//
52 "<a class='category' href='#{category_url}'>#{category.capitalize}</a>"
55 case categories.length