Static

If you’re reading this at leancrew.com, I hope you notice that the site is both faster and more stable than it has been for the past couple of months. If you’re reading it through an RSS feed, I’m just happy you can see it.

Yesterday morning, fed up with the recent server problems, I cobbled together a few scripts to turn ANIAT into a static site. As I’ve mentioned before, I have all of the Markdown source files for the site saved locally in a year/month folder system. From that, I generated a list of all the posts and publication dates, which came in handy when writing the scripts that built the whole site.

The scripts that build the pages—five at the moment, and growing—are ugly and need a little too much handholding to be called a “blogging system,” but it put together over 2,000 posts in short order, which is exactly what I needed. The site is up, nearly in the form I want, and the server is no longer complaining.

I did look into systems like Pelican and Jekyll and so on, but adapting my posts to fit their formats—or adapting them to fit my posts—was a more daunting task than I wanted to take on. So one of my “scripts” is a PHP template that generates a single post. Even though I know almost nothing about PHP (except that I want to keep it that way), this was relatively simple because I already had PHP templates from my WordPress setup that could be adapted. Also, I could continue to use my fork of Michel Fortin’s PHP Markdown Extra, which meant all my equations would render.

The biggest problem I had was dealing with dates. PHP has about 16,384 date functions, each of which is incompatible with all but a few of the rest. I’m sure real PHP programmers know which ones to steer away from, but I was adrift in the documentation and hit several rocks before getting back into the current.1

The PHP script/template for generating a page could be run directly from the shell, one file at a time, but I had no interest in doing that 2,000 times. So I wrote a Python program that ran through the list of posts and generated a 2,000-line shell script, each line of which ran the PHP script. The Python-to-bash-to-PHP bankshot was inelegant, but it only had to be done once. Now that all the old posts have been generated, I don’t have to run that long shell script again.

As with the PHP template files, I also lifted the CSS files from my WordPress setup, which is why the site looks more or less the way it used to. Same with the JavaScript that handles the syntax highlighting. Laziness saved me a lot of work.

One thing that was a little tricky was the list of recent posts over in the sidebar. I want that to look the same for every page on the site, and it has to be updated every time I add a new article. The only way I could think of to do that without regenerating every page was to have that list injected into the page by a JavaScript function. The JavaScript gets updated whenever a new post is published, but the pages that call it remain the same. The JavaScript file is generated by a little Python script that pulls information from the last twelve lines of that handy list of posts.

The biggest visible change left for the site is to have the home page show more than one post. Right now, it’s just a slightly edited version of the page for the most recent post. This again was a quick and dirty way to get the site up and running, but it isn’t what I want for the long term.

Internally, the biggest improvement will be an automated way to generate the RSS feed. At present, I have an <item> template that I fill in by hand and copy into the index.xml file. That’s crude even by my standards, but I can live with it for now. It’s rare that I post more than once a day.

I’m not ready to show my work yet; I want to get the full thing automated before I do that. But I did want to give a small indication of what’s going on behind the scenes and explain why the site doesn’t look or work quite like it used to. And I wanted to thank you who continued to visit despite the horrible performance problems. You’ve been very patient.

The last item on my blog to-do list is to find a new web host. The top contenders, based on recommendations by people who seem trustworthy, are Digital Ocean, Linode, and AWS. If you know of a good, up-to-date comparison of these services, shoot me a link on Twitter.


  1. Did I torture that metaphor enough?