• Web

Tumbling down

I played around a bit with Tumblr, and while it’s a bit too simplistic for me, it did have two features I really liked:

* Automatic formatting of IM conversations
* Automatically creating posts when an RSS feed (my flickr photostream, stumbleupon favorites, etc.) changes

As you can tell from the previous entry, I’ve implemented the automatic formatting using LiveJournal’s S2 programming language. Any post tagged “chat” gets turned into an HTML list with colored names.

For anyone curious on how it works, the following code gets run to output each journal entry:

var string tags = $e->get_tags_text();
if ($tags->contains(">chat<")) {
var string name = "";
var string prevName = "";
var string body = "";
var string c = "";
var bool foundName = false;
var int eol = 0;
var string nameColor = "";
var string lineColor = "";

print "<ul style='list-style-type: none; margin-left: 1em; padding: 0px; clear: both;'>";

foreach var int pos (0 .. ($e.text->length() - 1) )
{
if ($eol == 0) {
$c = $e.text->substr($pos, 1);
if ($foundName) {
$body = $body + $c;
} else {
$name = $name + $c;
}
if ($c == ":") {
$foundName = true;
}
if ($e.text->substr($pos,6) == "<br />" or $pos == ($e.text->length() - 1)) {
if($foundName or $lineColor == "") {
$lineColor = alternate("#eee","#ddd");
}
print "<li style="padding: 4px; border-left: 8px solid #aaa; margin: 0px; background-color: " +="+" $linecolor="$lineColor" +="+" ";";="";";" if($foundname)="if($foundName)" {="{" if($pos="if($pos" !="($e.text-">length() - 1)) {
$body = $body->substr(0,$body->length() - 1);
}
if($name != $prevName) {
$nameColor = alternate("#c00","#00c");
}
$prevName = $name;
print ""><span style="font-weight: bold; color:" +="+" $namecolor="$nameColor" +="+" ""="""">" + ehtml($name) + "</span>" + ehtml($body);
} else {
if($pos != ($e.text->length() - 1)) {
$name = $name->substr(0,$name->length() - 1);
}
print " padding-left: 1em;'>";
print ehtml($name);
}
print "</li>";
$eol = 5;
$name = "";
$body = "";
$foundName = false;
continue;
}
} else {
$eol--;
}
}
print "</ul>";
} else {
print $e.text;
}

As for the automatic posts, I’m working on a script that will automatically post new photos from my Flickr photostream, and another one that will make weekly posts of my StumbleUpon favorites. More about them soon!

Close Menu