Saturday, October 27, 2007

Blogger Hacks for Fun and Profit

I hadn't really given Blogger much credit until I noticed it's all Google code inside, which means two things right off the bat:

  1. It will probably work on everything.
  2. It will probably be easy to get into the code and play around.

Number one is important. While a skilled code craftsman appreciates the beautiful algorithms that might shave a few milliseconds off code execution, I am but a humble code-monkey, and as such I appreciate the ass-loads of brute-force slogging through browser inconsistencies followed by man-years of unappreciated testing that had to have gone into the code before release. There's code in there that just targets mobile clients, for fuck's sake. And you thought making a page-hugging footer work without tables was 't3h sh1t'. Google's got code just to mock your code.

But number two is the fun stuff. The Blogger API should look familiar to anyone who's dipped their toes into the murky waters of JSP. Lots of this kind of stuff:

<b:if cond="'data:post.numBacklinks"></b:if>
<dl class="'comments-block'" id="'comments-block'">
<b:loop values="'data:post.backlinks'" var="'backlink'"></b:loop>
<div class="'collapsed-backlink">
  <dt class="'comment-title'">
    <span class="'backlink-toggle-zippy'"> </span>
    <a href="" rel="'nofollow'"><data:backlink.title></data:backlink.title></a>
    <b:include data="'backlink'" name="'backlinkDeleteIcon'/"></b:include>
  <dd class="'comment-body">
  <dd class="'comment-footer">
    <span class="'comment-author'">
    <span class="'comment-timestamp'">

There's your if…then loop at the start, and your for loop over there… of course, they really need to include an INDEX on the loop to help us out, but there are ways to work around the limitation.

Anyway, it's a workable foundation. In the case of Blogger, most of the components (Links, About Me, etc.) are just black boxes to the database. You have access to a few members ("link" or "name"), but if you want to extend the structure you're SOL. Well… kind of.


If you want to use their data warehouse, you have to do it through them. But there's no restriction on how you use your fields. The Links List component on the right is an example.

Blogger gives you two fields: the URL and the Link Name. But most website names are dumb. A frantic, violent struggle for the table scraps of words left in the English Lexicon—what ones that haven't already been trademarked and copyrighted to death or stolen by some obscure punk band still playing in their mom's garage—that we then desperately try to assemble into a phrase which can, if you tilt your head sideways a bit, resemble the most meager sliver of our essence.

I mean, just look mine. "Revenge of D'oh!" Christ.

Anyway, I thought it would be far more useful if the website author's actual name could be associated with the link. But since we're only given two fields to work with, I have one doing double-duty. The "name" field is delimited, parsed, then through some fancy JavaScript-ery, appended to the link.

More to come.

No comments: