And money for nothing. Or something like that? Sorry, Mark Knopfler. I’ll pay more attention next time.
Anyways, let us be painfully aware that we can get Atom feeds for free. Not as in beer or speech, but as in ‘zero lines of code.’ How? Microformats.
You and meFormats
Almost a year has past since we last spoke of microformats, and way more than a year since our first encounter. Seems like only yesterday.
Remember hAtom? It’s like Atom, only embedded into your existing content’s HTML pages. The mofo site references the following example:
A normal, typical blog post:
<div class="post"> <h3>Megadeth Show Last Night</h3> <span class="subtitle">Posted by Chris on June 4th</span> <div class="content"> Went to a show last night. Megadeth. It was alright. </div> </div>
The same post with hAtom superpowers:
<div class="post hentry"> <h3 class="entry-title">Megadeth Show Last Night</h3> <span class="subtitle">Posted by <span class="author vcard fn">Chris</span> on <abbr class="updated" title="2006-06-04T10:32:10Z">June 4th</abbr> </span> <div class="content entry-content"> Went to a show last night. Megadeth. It was alright. </div> </div>
To you and I, eagerly searching for a review of last summer’s Megadeth show, there is no difference between the two. Our browsers render them the same. To a machine, however, the second post is chock full of semantic goodness.
This semantic goodness represents, in our HTML, the same information an Atom feed would provide. This leaves us with two paths of action for gettin’ our feed on: we can wait for feed readers to start speaking hAtom fluently, or we can have someone translate hAtom to Atom for us.
Subtlely Free Feeds
One year ago today Subtlety was released. Today it is re-released with a new feature: it can convert a page containing hAtom entries into an Atom feed. This means your feeds are now officially free.
We’ve actually been doing this for a while right here on Err. Our Feedburner feed points to this url: http://subtlety.errtheblog.com/O_o/29f.xml. It’s an Atom feed generated by Subtlety after parsing the hAtom elements on this site. On Err the Blog.
My ozmm blog is a static blog with no special RSS code. Instead, I point the Feedburner URL at a Subtlety Atom feed which is generated from the hAtom in the posts. Our Dynamite blog uses the same trick. See the pattern?
There’s no reason to ever write your own Atom feeds anymore. Sorry.
But what if I don’t want you hosting my feeds?
That’s fine, and acceptable. How about I just hand you the technology to do this on your own?
It goes like this:
$ gem install mofo $ cd rails_app/vendor/plugins $ gem unpack mofo
Then, here’s your controller:
class PostsController < ApplicationController def index @posts = Post.find(:all) end def atom target = url_for(:action => :index) render :xml => hEntry.find(target).to_atom(:title => 'whatever') end end
You can use this trick for dynamically generated feeds (changelogs or activity feeds, perhaps) or whatever else. Thanks, mofo.
Last Step: Cut the Code
Now go through your app and remove all the Atom code. Drop those extra plugins, remove those xml templates, cut out all the special logic, and enjoy simple Subtlety or profound mofo.
Have fun.
Wicked !! Thx
You guys rock so hard, you should start a megadeth blog.
I’ve been doing this for a while with my journal using “hAtom2atom:”http://lukearno.com/projects/hatom2atom/. This tools creates valid atom while you’re implementation currently don’t. Seems you forgot that one can use a global author and not need to have an author for each hentry.
Isn’t there a race condition in the atom call? As in: Rails is single threaded. If the request that Mofo (presumably) sends to this host for the index page is dispatched to the same mongrel instance (or whatever webserver you use), it will be queued to wait for the original request to ‘atom’ to finish, which is forever and will give a timeout. No?
You rock man! It means that you never have to write your own RSS feeds. It is just awesome!
Microformats FTW. An hCard → LDAP proxy would be a snap, based mostly on this:
http://thoughtbot.com/projects/ldap-ar-gateway
Really cool, didn’t know it was possible. Webservices that extract microformats from HTML really rock!
Eivind: We used to use that service but found it to be unreliable. Thus, we wrote our own. And oh yeah, the Err feed validates. Patches welcome!
@RobSanheim: You may be interested in an audio recording currently on my hard drive where a certain blog celebrity plays Megadeth tunes on his guitar.
hi my name is nilesh
You might also consider Dapper. No need to use a specific microformat.
@martin is right I think. There is a race condition in the atom call and you get a timeout error in dev mode.
Maybe change the implementation to use a ActionController:TestRequest to achieve this internally?
Supercool stuff.
It’s getting harder and harder for me to keep ignoring microformats…
This won’t work on development mode, since it requires doing another GET in parallell. Perhaps some render_to_string magic?
To get around the race condition in development just start up another server on saw port 3001. Then just set the host like so
url_for(:action => :index, :host => ‘localhost:3001’).
What about RDFa?
Getting around the race condition in development does not get around the race in production.
Rails is non-threaded, so if your mofo request happens to hit the same server as the initial atom request, the request will hang. Best I can tell, there is no way to work around this, save not performing an additional request.
Wow, the relevance of your blog is staggering, and I’m here to praise and to you to boost my own pagerank! Back to keeping my comment relevant. So you used to work for CHOW… Do you have any advise about microformats for recipes? I’m working on a site that is like a delicious for recipes… Reci-P… go figure… but we are trying to hook it up so the recipes are semantically organized… We’ve got tags and I’ve hooked them with the rel-tag semantic markup.. got any pointers for recipe ingredients, units of measure, styles of cooking? Anything would be a big help. Another question. Why is this blog so inactive? You have a good thing going. Why stop?
Hey there – running your suggestion on my site: VibeReview (NSFW, by the way) and I get “execution expired” errors from time to time. I am unable to replicate it reliably and I’m sorry to say that I don’t have much more info, but has anyone here had the same problem? The top line in the backtrace is this: timeout.rb:54:in `open’ and the message is simply “execution expired”
Thanks!
Chime in.