Mikkel Høgh

Coding the web since 1999

17 Sep 2012

How to configure Octopress for Drupal Planet syndication

Since I moved my blog to Octopress, I’ve been struggling with my blog posts not getting picked up by Planet Drupal.

When I started using Octopress, it only had a site-wide Atom feed, and despite my little experience with Ruby or Liquid, I managed to hack together category-specific feeds for Octopress. These were merged into Octopress core, so if you get the latest version from the master branch, you should have these.

Sadly, despite my feed being valid Atom 1.0, Planet Drupal does not parse it properly, and my blog posts were still not included in its feed. This might not be all that surprising to someone more familiar with the history of the aggregator.module, which is the feed aggregation module that ships with Drupal, that Planet Drupal uses for its syndication.

Politely said, this module is not one of the parts of Drupal core that gets the most attention, and its feed parsing code is not exactly state-of-the-art. In fact, it only supports a subset of the Atom spec and a particular version of the older and inferior RSS. Now, I won’t get into the nasty history of web syndication technology, but suffice to say that this is one of the instances where I find myself wishing that the Drupal community wasn’t so NIH-prone. (that goes for you, too, project.module).

So, long story short, if you want to be on Drupal planet, you have to implement a feed format it understands, so I made an old-school RSS format, that should correspond almost exactly to what Drupal itself outputs when it generates feeds.

The template

Create a file named planet_drupal.xml and fill it with this:

---
layout: nil
---
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="{{ site.url }}" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
  <title>Planet Drupal | {{ site.title | xml_escape }}</title>
  <link>{{ site.url }}/planet_drupal.xml</link>
  <atom:link href="{{ site.url }}/planet_drupal.xml" rel="self" type="application/rss+xml" />
  <language>en</language>
  <generator>Octopress</generator>
  <description>Planet Drupal RSS feed for {{ site.url }}</description>

{% for post in site.categories['Drupal'] limit: 10 %}
  <item>
    <title>{{ post.title | xml_escape }}</title>
    <link>{{ site.url }}{{ post.url }}</link>
    <dc:creator>{{ site.author | xml_escape }}</dc:creator>
    <guid isPermaLink="true">{{ site.url }}{{ post.url }}</guid>
    <pubDate>{{ post.date | date: "%a, %d %b %Y %H:%M:%S %z" }}</pubDate>
    <description><![CDATA[{{ post.content | expand_urls: site.url | cdata_escape }}]]></description>
  </item>
{% endfor %}

</channel>
</rss>

How to do it

  1. Download the feed template attached above.

  2. Put it somewhere in the source folder of your Octopress site.

    I have it at source/planet_drupal.xml, but the name and location should make no difference at all. Since I have it at the route of the source tree, my feed is available at http://mikkel.hoegh.org/planet_drupal.xml

  3. Change the {{ "{% for post in site.categories['Drupal'] limit: 10 " }}%} line to match the name of the category you want to make a feed of. In my case, the category name is Drupal. This is probably case sensitive, so be sure to be consistent when categorizing your posts.

  4. If you haven’t done so already, tag your posts with the right category to have them included in the feed.

    This is how this post is tagged, for reference. This is standard Octopress post metadata.

    ---
    layout: post
    title: "How to configure Octopress for Drupal Planet syndication"
    date: 2012-08-12 22:32
    comments: true
    categories: [ Drupal, Octopress ]
    ---
    [post body here]
    
  5. Redirect your current feed address or report your new feed address to the Drupal.org webmasters.