Feedburnerizing Typo, Part II

Paul Brown @ 2006-07-03T19:49:34Z

Last year, I wrote a rudimentary sidebar to display Feedburner feed links in Typo, but I didn't really get it to the point I wanted at the time. So, I took another fifteen minutes to rewrite the sidebar to work with the enhanced API, ditch the auto-subscribe chiclets, add links for category feeds, and muck with routes.rb. In routes.rb, I mapped a new set of feed URLs for Feedburner onto the controller that currently serves feeds, switched the existing mappings to a two-line controller that 301's to the Feedburner equivalents, and left holes so that people can subscribe directly to article-specific or tag-specific feeds if they wish. (The bonus in this approach is that autodiscovery gets taken care of for free, because the autodiscovery feed is one that gets 301'd.)

Just for grins, here's the two-line controller implementation:

class FbController < ContentController
  def redirect   
    headers["Status"] = "301 Moved Permanently"
    redirect_to "http://feeds.feedburner.com/Multifarious" +
      params[:type].to_s.capitalize + params[:id].to_s.capitalize
  end
end

Sometimes I think that the cornucopia of methods on some of the Ruby core classes (like capitalize on String) is overkill, and sometimes, it's convenient.

I hope that the enhanced setup is useful to any readers (since Feedburner should ensure QoS), but mostly I hope that it's transparent. (FWIW, NetNewsWire did the Right Thing and changed the feed URL for my self-subscription to the new one in response to the 301.) If for some reason you can't see this, let me know...

(comment bubbles) 0 comments

WordPress to Typo Migration, Part II

Paul Brown @ 2005-12-10T04:45:00Z

The initial migration (and a subsequent upgrade from 2.6.0 to svn trunk) was pretty much painless, but the database migration didn't take care of mapping permalinks or date queries from the WordPress scheme to the typo scheme. Enter a little mod_rewrite and Ruby (at which I'm a newbie).

The first step is to grab the query string on the old server, e.g., to grab the WordPress-style permalink:

http://oldblog/?p=69

to a new entry point in typo like:

http://newblog/wp/69

the required bit of mod_rewrite script is:

RewriteCond %{QUERY_STRING} p=([^&;]+)
RewriteRule ^/$ http://newblog/wp/%1? [R=301,L]

(The trailing ? drops the query string in the redirected URL, and back references use the % in place of the $.) The 301 response code is "moved permanently", so well-behaved clients should get the idea. The same technique applies to the query string-defined syndication protocols that WordPress uses for the RSS and Atom feeds.

The next bit of work in Ruby is a bit painful because of the way that the database migration script maps the IDs. (If I was in the mood, I could have modified the migration script to dump an id cross-references, but I wasn't and didn't.) The first piece is a new route in config/routes.rb:

map.connect 'wp/:wpid',
  :controller => 'articles', :action => 'wp'

And then a bit of Ruby in app/controllers/articles_controller.rb:

def wp
  begin
    wpid = params[:wpid].to_i
    case wpid
      when (109..109) then wpid = 97
      when (100..101) then wpid -= 15
      # etc.
    end
    # imitate the "read" method here...
  end

And that should do it. (So far, the most difficult part of Ruby is not typing a ; at the end of a line...)

(comment bubbles) 0 comments