Updated, loads of changes to layout parts
[blog.git] / _plugins / category_pages.rb
1 module Jekyll
2
3 class CategoryPage < Page
4 def initialize(site, base, dir, category)
5 @site = site
6 @base = base
7 @dir = dir
8 @name = 'index.html'
9
10 self.process(@name)
11 self.read_yaml(File.join(base, '_layouts'), 'category_index.html')
12
13 self.data['iscat'] = true
14
15 if category != 'index.html'
16 self.data['category'] = category
17 category_title_prefix = site.config['category_title_prefix'] || 'Category: '
18 self.data['title'] = "#{category_title_prefix}#{category}"
19 else
20 self.data['title'] = 'Categories:'
21 end
22
23 end
24 end
25
26 class CategoryPageGenerator < Generator
27 safe true
28
29 def generate(site)
30 dir = site.config['category_dir'] || 'categories'
31 if site.layouts.key? 'category_index'
32 site.categories.each_key do |category|
33 newpage = CategoryPage.new(site, site.source, File.join(dir, category), category)
34 site.pages << newpage
35 #categories << newpage.title
36 end
37 end
38 site.pages << CategoryPage.new(site, site.source, dir, "index.html")
39 end
40 end
41
42 end