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.
This article is obsolete, and the feeds generated from this site have some bugs that won't be fixed.
Entries
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 #> <entry> <title><% title %></title> <id>tag:example.org,<# print created[:10], #>:/<% pagepath %></id> <updated><# try: print updated except NameError: print time.strftime('%Y-%m-%dT%H:%M:%SZ',time.gmtime(modified)), #></updated> <link rel="alternate" href="http://www.example.org/<% pagepath %>" /> <content type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml"> <% body %> </div> </content> <summary type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml"> <# try: print thispage['page-description'], except TypeError: pass #> </div> </summary> <published><% created %></published> <# for tag in tags: print '<category term="'+tag+'" />', #> </entry>
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:
r2w.py -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 ./sort_feed.py > build/feed.atom
where sort_feed.py 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="http://www.w3.org/2005/Atom" xml:lang="en"> <id>tag:www.example.org,2010-10-10:</id> <title>Example Website</title> <author> <name>Author Name</name> <email>webmaster@example.org</email> <uri>http://www.example.org</uri> </author> <link rel="self" href="http://www.example.org/feed.atom" /> <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" type="application/atom+xml" title="Elena ``of Valhalla'' Webpage" />