Th.Oughts : Pyblosxom + git blogging

As part of trying about just anything to get the motivation to start blogging again, I decided to try something new and different. Drupal, that my blog was previously running on is an excellent full-featured blogging platform, but at times, it can make you feel like it's just too heavy and bloated if all you want to do is just put some text entries once in a while.

Well, the mention of text entries brought the first question to my mind : What am I most comfortable in as far as entering text is concerned ?

The answer to that would be whatever I use as part of my daily work routine. And things that I use for work : git, emacs, any shell (such as bash). Most importantly, most part of my work life is in a console, ofcourse, except for browsing for which I have firefox open in the other screen. Oh! I just love tiling window managers (sorry for digressing..)

If I had to make the change from Drupal, I had to get into something lightweight and so simple that even I could understand ;) That led me to Blosxom and family and the winner:

Pyblosxom.

First, because, it's written in Python, the language, that could be used on the web that I understand quite a bit. Second, it works with text files. I just wanted to get rid of databases. They just double your server requirements and I find working with text files much easier than working with databases.

So, this setup is an attempt to setup an environment that I am most comfortable in, easily make changes to to suit my needs and last but not the least, lightweight too. The main inspiration for the setup comes from Abhijit Menon-Sen's toroid.org.

From this point, I will focus on how git and pyblosxom work together. See the notes at the end of this post for a script to backup older entries from the Drupal database, the repository to a modified version of Pyblosxom (plugins mostly) that I use with my website, CSS, templates etc. Feel free to use them.

In the ideal case, you have a folder on your local system

mkdir blogging

Make this git aware

git init

On your remote system, i.e where your blog is served from by Pyblosxom, create a directory to track our local changes

mkdir blogging.git
git init --bare

Now, there are a few important considerations. First of all, when you push changes from your local system, you would want them to directly be moved to the location from where Pyblosxom is serving your pages (pyblog/entries) in my case. The other thing is that, Pyblosxom uses mtimes to sort blog entries and the unwanted effect of this is that if you posted an entry 2 months back and decided to edit/add some information today, the post would come to the top of your feed as if it's a new post. There are a few Pyblosxom plugins to prevent this behavior but I decided to use git to take care of this.

cat blogging.git/hooks/pre-receive

#!/bin/bash
WD=/home/bandan/pyblog/entries
rm -rf accessdata
for filename in \`find $WD -name "*.HTML"`
do
  mtime=`stat -c %y $filename`
  echo "$filename $mtime" >> accessdata
done

cat blogging.git/hooks/post-receive

#!/bin/bash
GIT_WORK_TREE=$HOME/pyblog/entries git checkout -f

while read line
do filename=`echo $line | awk '{print $1}'
mtime=`echo $line | awk '{print ""$2"" " " ""$3"" " "  ""$4""}'`
touch -d "$mtime" $filename
done < "accessdata"

Now back to your local system

git remote add blog
ssh://server/yourhome/blogging.git

Create a new entry

echo "First Blog entry " > firstblog.html
git add firstblog.html
git commit -m "First blog entry"
git push blog +master:refs/heads/master

And the next time you make a change or create an entry, you can just do a

git push blog

And because of the hooks, when you edit an already posted entry, the mtime will be preserved.

Other Notes :

I cooked up a small python script to pull blog entries from my drupal database along with the creation times and write them to text files. You can find it here

git://code.makefile.in/git/drupal2blosxom

The modified version of Pyblosxom plugins that I use on this website, templates and CSS are available at

git://code.makefile.in/git/pyblosxom

Comments

blog comments powered by Disqus