david hall icon

Blogofile Feeds

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


<% from datetime import datetime %>

  ${bf.config.blog_name}
  ${datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")}
  ${bf.config.blog_url}/atom.xml
  
  
  Copyright (c) 2010, you
  http://www.yoursite.com/iphone.png
  Blogofile
% for post in posts[:7]:
  
    
      you
      ${bf.config.blog_url}
    
    <![CDATA[${post.title}]]>
    
    ${post.permalink}
    ${post.updated.strftime("%Y-%m-%dT%H:%M:%SZ")}
    ${post.date.strftime("%Y-%m-%dT%H:%M:%SZ")}
% for category in post.categories:
    
% endfor
    ${post.title}]]>
    
  
% endfor

and georss.mako


<% from datetime import datetime %>

  
    ${bf.config.blog_name} Geo
    ${bf.config.blog_url}
    ${bf.config.blog_description}
    ${datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT")}
    Blogofile
    hourly
    1
    
        you Geo
        http://www.yoursite.com/iphone.png
        http://www.yoursite.com
        80
        80
        you
    
    
% for post in posts:
% if hasattr(post, "lat"):
    
      ${post.title}
      ${bf.config.blog_url}${post.permapath()}
      ${post.date.strftime("%a, %d %b %Y %H:%M:%S GMT")}
% for category in post.categories:
      
% endfor
    
    % if post.guid:
          ${post.guid}
    % else:
          ${post.permalink}
    % endif
      link]]>
      
    
% endif
% endfor
  

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...

2010-07-06