Pelican and the Static Web Site
Static websites and blogs are making a comeback. A Wordpress blog that makes a database call every time a web page is loaded is an incredible waste of resources. If you get fireballed[^1] and you're running a dynamic site, chances are the database server will give way before your bandwidth is used up.
Static blogging engines use local programs to turn markdown documents into articles and pages that can be copied to a host. These sites are lightning fast and very easy to manipulate. The platform I went with for this site is Pelican. It's based on Python and uses the Jinja2 template engine. There are a good array of themes waiting for you to hack around with.
The way Pelican works is as straight forward as it comes; you install the python app (
pip install pelican) and you're on your way. You can use
pelican-quickstart to get going fast. It will walk you through creating the proper config files and folder structure. It also installs a little
make applet that will quickly create a site from the content directory. The files it creates can easily be placed into a public Dropbox folder or used with a service like Site44 if you so choose.
What about portability? You wrote hundreds of posts on your Wordpress site, how do you get them out? This is one of those issue that comes up every time you try and change platforms. Wordpress can be exported into a few sites, but your data is always locked in a database somewhere. Pelican uses flat file markdown that's formatted with the meta data you'd like at the beginning. You can take those posts anywhere that accepts markdown. The post header looks like this:
Title: Pelican + Heroku + Cloud9
Tags: development, pelican, heroku
Excerpt: Some excerpt of the post for index.html
A static site uses next to no resources. This means hosting should be cheap or even free. With services like Site44 you can use your Dropbox as a host for free. I'm sure this is a fantastic solution for most people. Unfortunately I'm not most people. I wanted a site hosted on a service I trusted a little more. Enter Heroku. I created my first Heroku project a few months back, messing around with Django a bit. I loved the platform, and the free developer tier has more than enough resources for any project I'd dig into. I'm not trying to "ship" anything substantial. I just need a no frills place to host my side projects.
The problem with Heroku is it only works with certain languages, and no-language isn't an option. By default, there's no web server installed. If you're using Python, you normally use something like Gunicorn. Setting up Gunicorn as a basic HTML host is too much work. Luckily, there's a work around.
I came across an article outlining just how easy it is to host a static site on Heroku. Let me paraphrase here:
$ touch index.php
$ echo 'php_flag engine off' > .htaccess
That's it. You can even delete the
index.php file after your first push of code. Just enough for Heroku to think you've created a PHP app. The only issue I came across is the slug[^2] size. Heroku packages Apache up in the slug, so it weighs in at 9.5 MB. That's not breaking the bank or anything, but it's no featherweight either.
When I first began digging into this setup, I ran into an issue when trying to
git push my output directory to my Heroku app. The
make html command cleans the output directory first, and then refreshes all of it's content. Normally this would be great, but that cleaning also nixes the hidden git direcotry, breaking any future commit's you attempt to make. I thought about committing the entire working directory to my app, but that would mean a bigger slug along with messing with Heroku's Apache config files to redirect it to a different folder. I decided to pass.
The work around isn't too hard though, simply using
$ pelican -o output -s pelicanconf.py instead. This will update
/output with only the changed files, leaving
You're now rolling with a Heroku hosted static blog that was generated using Python. And it's fast as hell [^3].
An Everywhere IDE
You've made it this far. You're hosting a static blog in the cloud like a champ. The only problem is, it can only be edited from one computer. Setting up a python development environment is no easy task and not something you'll want to do a few times in several different locations, especially if it's just so you're able to post to your blog when and where you'd like.
Enter Cloud9. Cloud9 is an IDE in the cloud. It can be used with just about any modern web programming language and is chocked full of features. I've been using it to develop themes for my site as well as deploying it to Heroku. It's been a life saver. The IDE is free for up to one git based private workspace and unlimited public workspaces.
Aside from having a solid text editor, Cloud9's terminal is perfect for setting up and deploying your site. It has
easy_install ready to go, so setting up
pip and Pelican is no problem at all. And since it's in the cloud, I can edit my theme and post updates to my site from my work and home computers.
All of this isn't without a few overcome-able drawbacks. Since you're hosting from a slug that you're trying to keep as small as possible, image hosting is out of the question. Amazon's S3 will do this job just fine though, or you can use you photo hosting app of choice. Also there's no easy way to edit from a mobile device. While Cloud9 is great when sitting at a computer that's online, there's no way to post while on the go, or even from an iPad. I'm crossing my fingers that a Cloud9 iPad app is in the works. If this is a deal breaker for you, setting up an SSH server somewhere and using Diet Coda is a good solution. I'm going to give this a try next.
I'd recommend anyone who can work their way through a command prompt and would like a free, simple blog to give this setup a try. I'll be working through it and publishing my thoughts. My next endeviour is creating a theme. I've created the theme you see here, and you can check it out on Github.
[^1]: When a popular linked list style site bombards you with traffic, bringing you to a halt. Think Daring Fireball.
[^2]: A slug in Heroku's world is your code packaged up, ready to be fired at one (or many) or their server instances.
[^3]: The free tier of Heroku goes to "sleep" every 10 minutes and takes a few seconds to spin up. A service like Pingdom can keep it alive all the time if this is a concern.