Short URLs

May 21, 2009


Not wanting to miss anything on this short urls business, I’ve implemented something similar in nanoblogger.

How? With a shell script and symlinks, my dear Watson. As with all shell scripting this is probably something you can do drunk.

First I need to get a list of all my articles so that I can link to them. Next I take this permalink address, pipe it through sha1sum, take the last 10 characters and make a symlink from the permalink path and presto: short urls

The shell one-liner becomes something like this (note: I’ve put the echo in there so you can see what happens).

for i in $(find $NB_ARCHIVES -type d -wholename "*2???/*/*/*" -print)
    HASH=$(echo $i | sha1sum)
    echo ln -sf $i $NB_SHORT/${HASH:30:10}

This scripts can be dropped in your plugin directory, so that it runs after each update in nanoblogger.

In your short urls directory (here: you can just use ls and grep to find out which short url links to what article.