A New Blog!
December 03, 2012Recently, I decided to move a new blogging setup. Previously, I used a self-hosted Wordpress install, then a custom Django app, and briefly Posterous.
I wanted a setup that:
- does not require a database
- generated static html pages
- allowed me to use whatever text editor I wanted (ie. Vim)
- hackable if I needed it do something ‘unsupported’
- Python-based preferable
I evaluated the following alternatives:
-
Octopress is Ruby-based blogging framework using the Jekyll static site generator with publishing to Github. Octopress makes it really easy to setup a blog and push to Github for hosting, but I prefer to do my own hosting.
-
Plain Jekyll. It seems a lot of developers use Jekyll with some type of external automation. But it being Ruby-based meant it would not be immediately hackable.
-
Pelican is a Python-based blogging framework. It looked pretty good on paper (Python-based, Markdown posts, feed, syndication), but it was too complicated for my taste.
I eventually found this post by Nicolas Perriault about building a static site generator with Flask. The complete code is in one file and is pretty easy to understand and hack.
Using Boto, you could even easily publish directly to an AWS S3 bucket for direct hosting using S3.
To preview of your blog:
$ python site serve -d
This will run a local Werkzeug web server on http://127.0.0.1:5000/
serving all of your content.
To generate static HTML files from your posts:
$ python site build
This will put all static content into a ./build
directory. Just upload to those files to your /var/www
or wherever you want your static blog served from.
This setup has the following dependencies:
- Flask (Jinja2 and Werkzeug)
- Fabric (for automated publishing)
- PIL (for creating image thumbnails)
- Pygments (for code syntax highlighting)
- argh (for command-line options configuration)
- Frozen-Flask
- Flask-FlatPages
- Flask-Markdown
- Flask-Assets
PIL and Fabric are really optional, but are helpful automation. Pygments is useful for automatic syntax highlighting of code snippets. I am pretty satisfied with how the setup has turned out so far.