Monday, July 19, 2010
This site has modified feeds to what comes out of the Blogofile v0.6 box, and instead of offering either atom or rss feeds, I’m just providing an atom feed for the main content (limited to the 7 latest) and a georss variant (unlimited) for anyone who wants that. Bruce (we worked on the GeoTagICon project) sometimes imports my geo-stream into his Bioneural map, when he can track down my latest offering that is, sorry to duck and dive so much.
So, if anyone wants to do the same, here’s how I did it.
Instead of the feeds being both called index.xml and sitting in their respective feed and atom folders, they both sit at the top level and are called atom.xml and georss.xml. Additionally, I have done away with the replication of category feeds in the Archives section, there is now just an atom feed. (They should all validate - they did last time I looked!)
Controller files
There are now individual controller files for the atom and georss files, instead of the previous one feed file. So, remove the feed.py file and replace it with;
atom.py
from blogofile.cache import bf
def run():
write_feed(bf.posts, bf.util.path_join(bf.config.blog_path), "atom.mako")
def write_feed(posts, root, template):
root = root.lstrip("/")
path = bf.util.path_join(root,"atom.xml")
bf.logger.info("Writing Atom feed: "+path)
bf.writer.materialize_template(template, path, {"posts":posts, "root":root})
and georss.py
from blogofile.cache import bf
def run():
write_feed(bf.posts, bf.util.path_join(bf.config.blog_path), "georss.mako")
def write_feed(posts, root, template):
root = root.lstrip("/")
path = bf.util.path_join(root,"georss.xml")
bf.logger.info("Writing GeoRSS feed: "+path)
bf.writer.materialize_template(template, path, {"posts":posts, "root":root})
now you have to alter the the categories.py file to only write the atom.xml file (again it sits at the same level as the corresponding index file), replace the following;
#Write category RSS feed
rss_path = bf.util.fs_site_path_helper(
bf.config.blog_path, bf.config.blog_category_dir, category.url_name,"feed")
bf.controllers.feed.write_feed(category_posts,rss_path,"rss.mako")
atom_path = bf.util.fs_site_path_helper(
bf.config.blog_path, bf.config.blog_category_dir, category.url_name,"feed","atom")
bf.controllers.feed.write_feed(category_posts,atom_path,"atom.mako")
with
#Write category Atom feed
atom_path = bf.util.fs_site_path_helper(
bf.config.blog_path, bf.config.blog_category_dir,
category.url_name)
bf.controllers.atom.write_feed(category_posts,atom_path,"atom.mako")
Remember to alter the url string for the new feed in the head.mako and map.mako template file (if you have one), plus any other stand-alone pages - such as (with mine) the about.html.mako and archives.html.mako files.
Feed templates
The two revised feed templates are as follows,
atom.mako
<?xml version="1.0" encoding="UTF-8"?><% from datetime import datetime %>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">${bf.config.blog_name}</title>
<updated>${datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")}</updated>
<id>${bf.config.blog_url}/atom.xml</id>
<link rel="alternate" type="text/html" hreflang="en" href="http://www.yoursite.com/" />
<link rel="self" type="application/atom+xml" href="${bf.config.blog_url}/atom.xml" />
<rights>Copyright (c) 2010, you</rights>
<logo>http://www.yoursite.com/iphone.png</logo>
<generator uri="http://blogofile.com/">Blogofile</generator>
% for post in posts[:7]:
<entry>
<author>
<name>you</name>
<uri>${bf.config.blog_url}</uri>
</author>
<title type="html"><![CDATA[${post.title}]]></title>
<link rel="alternate" type="text/html" href="${post.permalink}" />
<id>${post.permalink}</id>
<updated>${post.updated.strftime("%Y-%m-%dT%H:%M:%SZ")}</updated>
<published>${post.date.strftime("%Y-%m-%dT%H:%M:%SZ")}</published>
% for category in post.categories:
<category scheme="${bf.config.blog_url}" term="${category}" />
% endfor
<summary type="html"><![CDATA[<a href="${post.permapath()}">${post.title}</a>]]></summary>
<content type="html" xml:base="${post.permalink}"><![CDATA[${post.content}]]></content>
</entry>
% endfor
</feed>
and georss.mako
<?xml version="1.0" encoding="UTF-8"?><% from datetime import datetime %>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:georss="http://www.georss.org/georss"
>
<channel>
<title>${bf.config.blog_name} Geo</title>
<link>${bf.config.blog_url}</link>
<description>${bf.config.blog_description}</description>
<pubDate>${datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT")}</pubDate>
<generator>Blogofile</generator>
<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<image>
<title>you Geo</title>
<url>http://www.yoursite.com/iphone.png</url>
<link>http://www.yoursite.com</link>
<width>80</width>
<height>80</height>
<description>you</description>
</image>
<atom:link rel="self" href="http://www.yoursite.com/georss.xml" type="application/rss+xml" />
% for post in posts:
% if hasattr(post, "lat"):
<item>
<title>${post.title}</title>
<link>${bf.config.blog_url}${post.permapath()}</link>
<pubDate>${post.date.strftime("%a, %d %b %Y %H:%M:%S GMT")}</pubDate>
% for category in post.categories:
<category><![CDATA[${category}]]></category>
% endfor
<georss:point><![CDATA[${post.lat} ${post.lng}]]></georss:point>
% if post.guid:
<guid>${post.guid}</guid>
% else:
<guid isPermaLink="true">${post.permalink}</guid>
% endif
<description><![CDATA[<a href="${bf.config.blog_url}${post.permapath()}">link</a>]]></description>
<content:encoded><![CDATA[${post.content}]]></content:encoded>
</item>
% endif
% endfor
</channel>
</rss>
The only thing to watch for is the next Blogofile update, the structure will probably change somewhat, but I’ll get around that when and if it happens…