From 66916f57a71b3d7aeb1465b049ed701fbf65a68c Mon Sep 17 00:00:00 2001 From: Mikkel Hoegh Date: Wed, 5 Oct 2011 00:24:13 +0200 Subject: [PATCH] First attempt at creating per-category Atom feeds. --- .../source/_includes/custom/category_feed.xml | 28 +++++++++++++++ plugins/category_generator.rb | 36 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 .themes/classic/source/_includes/custom/category_feed.xml diff --git a/.themes/classic/source/_includes/custom/category_feed.xml b/.themes/classic/source/_includes/custom/category_feed.xml new file mode 100644 index 0000000..616642f --- /dev/null +++ b/.themes/classic/source/_includes/custom/category_feed.xml @@ -0,0 +1,28 @@ +--- +layout: nil +--- + + + + {{ page.title | xml_escape }} | {{ site.title | xml_escape }} + <![CDATA[{{ page.title }} | {{ site.title }}]]> + + + {{ site.time | date_to_xmlschema }} + {{ site.url }}/ + + + {% if site.email %}{% endif %} + + Octopress + + {% for post in site.categories[page.category] limit: 5 %} + + <![CDATA[{{ post.title | cdata_escape }}]]> + + {{ post.date | date_to_xmlschema }} + {{ site.url }}{{ post.id }} + + + {% endfor %} + diff --git a/plugins/category_generator.rb b/plugins/category_generator.rb index d9357bc..bb5fd32 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 . + # +category_dir+ is the String path between 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.