I really like writing about my projects and other things I'm working on, but it's usually hard to get started. Writing with tools I love, like vim and markdown, makes it a lot easier. Especially when these are the tools I'm already using on a daily basis. But having some easy way to manage this collection of thoughts is really what makes the difference for me. Octopress makes it easy. This is how easy it is to set up a new post and generate a web page from it:

$ cd blog
$ rake new_post["Start Writing with Octopress"]
  Creating new post: source/_posts/2013-08-16-start-writing-with-octopress.md
$ echo "Hey there" >> 2013-08-16-start-writing-with-octopress.md
$ rake generate

Basically, Octopress takes jekyll (an awesome static site generator) and wraps it up with everything you need (and more) to start publishing things you write. It has plugins for things like github, twitter, video, code snippets, and more. It just takes a few minutes to set up a site (start here).

Deploying

Now that you've got your static site generated, you have to figure out how to publish it. The great news is that since you already have your site versioned with git, it's really easy to publish it for free on github. I already had a VPS set up, so I decided to learn a little more and host it on that. I ended up doing something similar to the instructions here, using a git post-receive hook on my server.

This is what my post-receive hook looks like:

#!/bin/sh
# Deploy blog after push

GIT_REPO=$HOME/blog.git  
TMP_GIT_CLONE=$HOME/tmp/blog  
PUBLIC=/srv/www/blog/

echo "cloning repo"  
mkdir -p $HOME/tmp/ >/dev/null  
git clone $GIT_REPO $TMP_GIT_CLONE >/dev/null  
cd $TMP_GIT_CLONE

echo "bundle install"  
bundle install >/dev/null

echo "generating static site"  
rake generate >/dev/null

echo "syncing site to public directory"  
rsync -avhP public $PUBLIC >/dev/null

echo "cleaning up"  
rm -rf $TMP_GIT_CLONE >/dev/null  

This is about as simple as it gets, and it could certainly be more robust, but it works!

I can still push my site to github, which is nice because it keeps my posts versioned even when I'm not ready to publish them, and make working from multiple computers easy. And when I'm ready to publish my work, if I have my new repository on the server set up as a remote:

$ git remote add deploy deployer@myserver.com:~/myrepo.git

Then all I have to do to publish my site is push it to deploy:

$ git push deploy master

Update: I tried ruhoh a while back before I switched to octopress. I didn't really like it at the time because it didn't do everything I wanted it to do. But it looks like it's come a long way since then, and it might be a good alternative to octopress/jekyll now.

Tags: linux, git, blog