Hairy Sun

Matt's Blog on Some Geeky Topics

Creating Category Feeds in Octopress

The static blog generator, Octopress, does not generate per category RSS feeds by default. I thought I would need a plugin to do this but it is quite easy and a plugin is overkill. All that you need to do is create a feed file with the appropriate filtering to limit the category.

To create a per category feed, copy the default feed source/atom.xml file to say source/emacs.xml. I updated the <title> value and the for post loop to only use the emacs categories. Here is my file:

Category specific feed (see for loop). (emacs.xml) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
---
layout: nil
---
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title>{{ site.title | xml_escape }} - Emacs</title>
  <link href="{{ site.url }}/atom.xml" rel="self"/>
  <link href="{{ site.url }}/"/>
  <updated>{{ site.time | date_to_xmlschema }}</updated>
  <id>{{ site.url }}/</id>
  <author>
    <name>{{ site.author | xml_escape }}</name>
    {% if site.email %}
      <email>{{ site.email | xml_escape }}</email>
    {% endif %}
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  {% for post in site.categories.emacs limit: 20 %}
  <entry>
    <title>{{ post.title | xml_escape }}</title>
    <link href="{{ site.url }}{{ post.url }}"/>
    <updated>{{ post.date | date_to_xmlschema }}</updated>
    <id>{{ site.url }}{{ post.id }}</id>
    <content type="html">{{ post.content | expand_urls: site.url | xml_escape }}</content>
  </entry>
  {% endfor %}
</feed>

Comments