Fun with Pelican
The barrier to entry for starting my own blog was twofold:
- how to format it
- how to get it on the Web
Formatting wasn’t out of the question — I know how to write HTML. For my blog at EmbeddedRelated.com I have a Python script I wrote that generates HTML from an IPython notebook, converting the Markdown and putting in minor tweaks.
But that’s just the content. These days, a snazzy website means putting in CSS and headers and footers and links to Twitter and Reddit and some kind of commenting thingy and a site history and all that crap. Ugh.
Actually getting it on the Web is less problematic. If you want to publish something on the Web for free, there are plenty of places. Blog sites like Blogger or Tumblr or Wordpress are fine for basic blogs. But I get spoiled by having MathJax and managing my posts in version control, and being able to tweak little things. Another option is using the code-hosting sites GitHub or Bitbucket – these both allow you to publish a repository as a static website for free. They have their quirks, but they’re a much better match for hackers.
Formatting, and the path to Pelican
Back to the formatting problem: there are a whole bunch of static site generators out there; the big one is Jekyll, which is what GitHub uses for its pages. But it’s in Ruby. And I have nothing major against Ruby, it just screams “learning curve” to me.
Because… well, I’m getting older and more impatient, and my brain is already stuffed full of things I have to remember to get through the day, and adding more complexity to the mix is not something I really want. I put up two websites in 2008 and 2009 after learning PHP and Drupal (sorry, I won’t share them, you’ll just have to take my word for it), and a few years later both of them broke. I didn’t change a single darned thing. But something changed in the Apache or PHP configuration of the hosting service, and in the meantime I was busy and my PHP familiarity had been displaced by other things. I know if I was using PHP often I’d probably be able to fix them. But I don’t. And I have no more interest in that language. It’s like Legos. Looks really cool at first, you can make a bunch of gears and axles to make real machinery out of easy-to-assemble plastic parts, but then you find if you use them for something real, there’s too much friction and you start getting little bits of plastic dust eroding away, and sooner or later it just doesn’t work right. If you want machinery that works well, you have to upgrade to something real. Or just get used to replacing the plastic bits. So no more PHP. It takes up too many brain cells.
And that’s why I don’t really want to learn Ruby. Doesn’t matter if 99.9% of the time Jekyll doesn’t need you to modify one damn line of code. The point is, websites are like machinery. You just can’t expect them to work like a black box. You can try, and most of the time they’ll do fine (which is why software is wonderfully more reliable than hardware when you put it together right), but I want to get my hands dirty so I can keep things running smoothly.
So that meant Python, because I use it enough that my incremental investment in website infrastructure would be minimal, and I could figure out what goes on underneath the hood. I looked around and the Nikola and Pelican site generators seemed to be the most prevalent. What tipped me over the edge to Pelican, among other things, is that some of the blogs out there are written directly in IPython notebooks. So here we are.
Pelican is pretty easy to use. It’s a Python package you install
pip, and it comes with some scripts that setup a blog.
Once you have your site directories setup and you add or update
content, you just type
pelican and it does all the work. Yay!
I did have a bit of a Drupal flashback in that some of the
bells and whistles aren’t well-documented, and it seems that stuff
works just like magic, with no apparent mechanism, but I’ve gotten
So look, I can keep using equations like $ a^2 + b^2 = c^2 $
in Markdown with the usual
inline code bits or
standalone code blocks phooey("hey"); // with syntax highlighting!
and all the goodies I’m used to. Whee!
The hosting problem
Okay, first thing I needed was a domain name of my own. I wanted PERMANENCY. None of this myuser.blogger.com or myuser.bitbucket.com stuff. My data is MINE. It took me a while to come up with something that seemed to fit right, and wasn’t too goofy or serious.
Then back to GitHub or Bitbucket. Hmmm. After reading the fine print, it looks
like GitHub is almost perfect; you can link your own custom domain to their
site generators, but GitHub doesn’t give you private repositories for free.
I really didn’t want to publish my site as a public repository. If you want
to screen-scrape it to violate my copyright, go ahead, but I’m not going to
git clone my website in 15 seconds. Bitbucket does let you publish
static sites from a free private repository, but they won’t let you use
custom domains, at least not right now. Humph.
Well, I already have an account at NearlyFreeSpeech.net. It’s a great hosting service for hackers. It’s pay-for-use, and it’s cheap. No $7.99 a month subscription or whatever. As of 2015 — it looks like maybe it’s gotten cheaper since I joined in 2007 — the rates are $0.15 - $0.25 per gigabyte of data transfer, $1.00 per gigabyte per month of data storage, and either a penny a day for dynamic sites (PHP + whatever) or FREE for static sites. You could run a static site for a year and maybe it costs you a few pennies.
They handle domain registration as well; the cost varies by
the type of domain — if you want
.com it’s presently $9.34 a year, whereas
if you want to be cheap you can use
.work for only $3.49 — and I like
service for $3.29 a year. Sorry, if you want to find out my mailing address and phone number
you have to use other means besides a WHOIS service.
Then there’s DNS so I can link the
not-just-embedded.com domain to a hosted site on NearlyFreeSpeech.net
rather than actually having to create some server, and they give a discount
if everything is through them: only a penny every nine days, so that’s about 41
cents a year.
Total price: aside from the data transfer and storage, $13.04 per year. (If you wanted to be cheap and forego the custom domain name, you could publish for free via NFS with just the data transfer and storage costs.) If this site somehow gets a lot of traffic so my costs go up significantly, then I’ll put up some minimal ads.
Anyway, I found an article on how to post website updates on NearlyFreeSpeech.net with Git, and it works like a charm. Woot!
Pelican, Pelican, Pelican
I’m still working my way through the Pelican features I need.
Here are some of the articles I’ve used to get started quickly, in case you’re interested in doing something similar: