Generating Atom Feeds with rest2web

As mentioned in the about page, this website is built from reStructuredText sources using rest2web; as far as I know there are no pre-made solutions to generate atom feeds with the same tools, but it isn't hard to to it.

It seemed that the easiest approach would have been to generate atom entries using rest2web, and then join them together in a feed using some other tool.


To generate feed entries you need an .ini file that sets target_directory and compare_directory to some value different from your main r2w.ini and a template file like the following one:

<# import time #>
<title><% title %></title>
<id>,<# print created[:10], #>:/<% pagepath %></id>
    print updated
except NameError:
    print time.strftime('%Y-%m-%dT%H:%M:%SZ',time.gmtime(modified)),
<link rel="alternate" href="<% pagepath %>" />
<content type="xhtml">
   <div xmlns="">
      <% body %>
<summary type="xhtml">
   <div xmlns="">
    print thispage['page-description'],
except TypeError:
    pass #>
<published><% created %></published>
for tag in tags:
    print '<category term="'+tag+'" />',

This uses two uservalues from each source page: created, and updated; the former is mandatory and should never change, while the latter can be omitted, and the file modification time will be used. They should both be in the format required by the atom specs

You can then launch rest2web with: -t src/$FEED_TEMPLATE.txt $FEED_CONF.ini

to generate entries for every page.

Feed generation

To collect the entries in a single feed file I use the following commandline:

find $BUILD/*/* -name "*.html" | grep -v index.html | \
xargs ./ > build/feed.atom

where is a simple script that sorts the entries by date, keeps the latest 25 ones and adds the following header to output an atom file.

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="" xml:lang="en">

<title>Example Website</title>
     <name>Author Name</name>
<link rel="self" href="" />
<rights> © 2010 Author. Some rights Reserved</rights>

For this task, I'm still using a quick and dirty python script that is not fit for publishing, but I will probably have to rewrite it and it will be available on this page.

Feed references in the site

The following lines go in the <head> section of the site template, so that site subscribing with browsers such as firefox works:

<link rel="alternate"
   href="<% path_to_root %>feed.atom"
   title="Elena ``of Valhalla'' Webpage" />
Send a comment: unless requested otherwise I may add it, or some extract, to this page.

Return to Top