diff options
author | Frederic Hemberger <mail@frederic-hemberger.de> | 2011-10-16 04:58:14 -0700 |
---|---|---|
committer | Frederic Hemberger <mail@frederic-hemberger.de> | 2011-10-16 04:58:14 -0700 |
commit | d84daa2a882e238edc40871d0fdd2f41ff9f51a8 (patch) | |
tree | e263f76cd4e70bcc3c2028d5116f0b3c30f642b3 /plugins | |
parent | 21803814bc2d30660fe7e83fb6894c37ea886201 (diff) | |
parent | e1d680ff112952d88f9b9f5fd92d33f9a9b739db (diff) | |
download | my_new_personal_website-d84daa2a882e238edc40871d0fdd2f41ff9f51a8.tar.xz my_new_personal_website-d84daa2a882e238edc40871d0fdd2f41ff9f51a8.zip |
Merge pull request #201 from mikl/category-feeds
Adds per-category Atom feeds.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/category_generator.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/plugins/category_generator.rb b/plugins/category_generator.rb index d9357bc8..bb5fd329 100644 --- a/plugins/category_generator.rb +++ b/plugins/category_generator.rb @@ -48,6 +48,35 @@ module Jekyll end + # The CategoryFeed class creates an Atom feed for the specified category. + class CategoryFeed < Page + + # Initializes a new CategoryFeed. + # + # +base+ is the String path to the <source>. + # +category_dir+ is the String path between <source> and the category folder. + # +category+ is the category currently being processed. + def initialize(site, base, category_dir, category) + @site = site + @base = base + @dir = category_dir + @name = 'atom.xml' + self.process(@name) + # Read the YAML data from the layout page. + self.read_yaml(File.join(base, '_includes/custom'), 'category_feed.xml') + self.data['category'] = category + # Set the title for this page. + title_prefix = site.config['category_title_prefix'] || 'Category: ' + self.data['title'] = "#{title_prefix}#{category}" + # Set the meta-description for this page. + meta_description_prefix = site.config['category_meta_description_prefix'] || 'Category: ' + self.data['description'] = "#{meta_description_prefix}#{category}" + + # Set the correct feed URL. + self.data['feed_url'] = "#{category_dir}/#{name}" + end + + end # The Site class is a built-in Jekyll class with access to global site config information. class Site @@ -63,6 +92,13 @@ module Jekyll index.write(self.dest) # Record the fact that this page has been added, otherwise Site::cleanup will remove it. self.pages << index + + # Create an Atom-feed for each index. + feed = CategoryFeed.new(self, self.source, category_dir, category) + feed.render(self.layouts, site_payload) + feed.write(self.dest) + # Record the fact that this page has been added, otherwise Site::cleanup will remove it. + self.pages << feed end # Loops through the list of category pages and processes each one. |