_      _            _
         _ __ ___ (_) ___| | __  _ __ | |
        | '_ ` _ \| |/ _ \ |/ / | '_ \| |
        | | | | | | |  __/   < _| | | | |
        |_| |_| |_| |\___|_|\_(_)_| |_|_|
                  | |
                  |_|       Thoughts on (technical) stuff...
You're from: 23.22.252.150

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).

#!/bin/bash
NB_ARCHIVES=/home/miekg/miek.nl/blog/archives
NB_SHORT=/home/miekg/miek.nl/s
for i in $(find $NB_ARCHIVES -type d -wholename "*2???/*/*/*" -print)
do
    HASH=$(echo $i | sha1sum)
    echo ln -sf $i $NB_SHORT/${HASH:30:10}
done

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

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

Posted in: nanoblogger

3 comments

The only trouble is that the latest blog article does not get a short link, as the shorts links are calculated before the article gets a directory in the archive directory.
This article can now found:

cd s; ls -l | grep short
lrwxrwxrwx 1 miekg miekg 55 May 21 00:38 497728516a -> /home...


With http://www.miek.nl/s/497728516a.

Nice to have for twitter and the Changelogs in rdup.
Some foo later and it is completely integrated in my templates. So people can actually use them to link to my site.

Comments are closed

If you really, really want to comment, please mail miek@miek.nl.

0 comments in moderator queue