Sweet pyblosxom Hacks

Just having a blog tool isn't enough. You have to hack it. Make it your own. Here's what I've done with pyblosxom, since setting up 88mph.

RSS 2.0 Flavour for Pyblosxom

Just drop it in, and make two small changes! pyblosxom-rss-flavour.tar.gz

Cheap and Dirty Secure Email Interface

Here's how to get the contents of an old-style GPG-signed email into your pyblosxom data directory, care of procmail.

First we have to verify the signature of the content, so we pipe the body of the email into GPG. In this case, I'm not specifying a key to verify against, because I only have one key in my public keyring, but you could very well have a keyring of all your blog-posting friends, so everyone could post to it. Note that the message is cloned in procmail, so it's passed on to the next block too.

:0 Wcb: .lock.gpgverify
* ^TO_.*jdub\+weblog@example.com
| /usr/bin/gpg --batch --verify --keyring /home/jdub/.gnupg/pubring.gpg 2> /dev/null

The following block only runs if the preceeding recipe completed successfully. So, if the signature did not verify, it's skipped entirely. We sed out the signing mess, leaving us with just the content of the email. It's dropped directly into the pyblosxom data directory, with a filename based on the UNIX time.

:0 ab: .lock.gpgweblog
* ^TO_.*jdub\+weblog@example.com
| sed -e "/SIGNED MESSAGE/,/^$/d" -e "/BEGIN PGP/,/END PGP/d" > /home/jdub/bin/pyblosxom/data/$(date +%s).txt

And here's a quick little client script that will send the right thing for you:

#!/bin/sh
TEMPLATE=/home/jdub/bin/blog.template
BLOGFILE=/tmp/blog.$USER.$$
MAILTO=jdub+weblog@example.com

cp $TEMPLATE $BLOGFILE
MTIME=$(stat -c %Y $BLOGFILE)
vim -c 'set tw=76 expandtab nosmartindent' $BLOGFILE

if [ $(stat -c %Y $BLOGFILE) -eq $MTIME ] || diff -Bwq $TEMPLATE $BLOGFILE 2>&1 > /dev/null; then
	echo "No changes, weblog not updated."
else
	if gpg --clearsign $BLOGFILE; then
		if [ -x /usr/bin/mutt ]; then
			MAILER=mutt
		else
			MAILER=mail
		fi
		$MAILER -s "weblog entry" $MAILTO < $BLOGFILE.asc
		rm -f $BLOGFILE*
		echo "Weblog update sent!"
	else
		echo
		echo "Signing failure: $BLOGFILE"
	fi
fi

pyblosxom -> Advogato

I like having my own blog, but I also enjoy participating in the Advogato community, so I worked out a quick way of shunting pyblosxom entries off to my Advogato diary once a day. First, you need to create an advogato flavour for your blosxom. For a quick start, just copy your html flavour, and clear the head and foot templates. Then you need to set a cron job for the following script. Mine is set to run at 2359, every day:

#!/bin/sh
BLOG=/tmp/p2a.jdub.$$

# download today's blog
/usr/bin/wget -qO $BLOG $(date +"http://www.gnome.org/~jdub/blog/%G/%m/%d/?flav=advogato")

# check if there's any content
if [ "$(wc -l $BLOG | cut -d' ' -f7)" != "0" ]; then
	/home/jdub/bin/advodiary --source=$BLOG > /dev/null
fi

# clean up
rm -f $BLOG