Rod Waldhoff's Weblog  

Radio Tidbits

First Posted: 11 April 2003

Introduction

At the time I'm writing this (11 April 2003), I've been using Radio Userland for about two weeks, and I haven't poked around with Radio scripting very much in that time. (Frankly, I don't even know what language Radio scripting is using and/or is derived from. Python?) Nevertheless, I've learned a few things and thought I would try to share some of them here. (If for no other reason, to reciprocate for what I've learned from others who posted their Radio hacks.)

I hope to update this document from time to time as I learn new tricks and come to understand the Radio framework and scripting language a bit better.

Static Macros

First Posted: 11 April 2003

If you have a block of HTML that you'd like to use in a number of templates, you can define a simple <%macro%> for it. To do this, create a file named myMacro.txt containing something like:

on myMacro() {
	local (htmlText = "");
	htmlText = htmlText + "<!-- here's my macro -->\n";
	htmlText = htmlText + "<hr size=\"1\" noshade=\"true\">n";
	htmlText = htmlText + "Text of My Macro\n";
	htmlText = htmlText + "<hr size=\"1\" noshade=\"true\">n";
	htmlText = htmlText + "<!-- end my macro-->\n";
	return htmlText;
}

and drop it into your RADIO_HOME/Macros directory. Then invoke it via <%myMacro()%>. You can do more interesting things with this as well.

To post comments on this section, please use this blog entry.

Waypath It!

First Posted: 11 April 2003

The Google It! macro, if you've never seen it, is a Radio Userland macro that lets one add a line like <%radio.macros.googleIt(<%itemNum%>)%> to the #itemTemplate in order to generate a link that searches Google for the title of the current item. See my weblog or a number of others for examples of this.

Waypath.com is a sort of weblog search engine. Among other features, you can point waypath to a blog entry (really any web page) and find a list of related weblog entries (for some definition of "related"). For the few examples I tried it with, this seemed to work pretty well. I thought it would be fun to add a "Waypath It!" link to my item template, just like the "Google It!" macro Radio provides. And here it is:

<%
  local (adrpost = @weblogData.posts.["<%paddedItemNum%>"]);
  return ("<a href=\"http://nav4.waypath.com/rwn.jsp?url=" + 
     string.urlEncode(
        "http://radio.weblogs.com/0122027/" + 
        date.year(adrpost^.when) + 
        "/" + 
        string.padWithZeros(date.month(adrpost^.when),2) + 
        "/" + 
        string.padWithZeros(date.day(adrpost^.when),2) + 
       ".html#a<%itemNum%>") +
     "\" title=\"view related weblog entries from waypath\">waypath</a>")
%>

See my weblog for examples of this.

I added this directly to my #itemTemplate. It'd be nice to put this into a little macro so all one needs to do to invoke it is <%waypathIt(<%itemNum%>)%>, but the same strategy that works for static macros (dropping them into your RADIO_HOME/Macros directory) doesn't seem to work here. I think maybe I need to create one of those .ftsc files, but it's not clear to me how to do that.

This would be a whole lot easier, of course, if I didn't have to generate the permalink URL "manually". Note to the Radio development team, a <%permalinkUrl%> macro would be really handy. A macro that generates the homepage URL (e.g., "http://radio.weblogs.com/0122027/") would be handy too, but I suspect there's a way to get that I just haven't figured out yet.

To post comments on this section, please use this blog entry.