Blog Rewrite In Go

Today I rewrote all of the code I use to generate the static HTML for my blog. The code for my blog started out as a simple Python script, and over time evolved into incredibly slow and unmaintainable spaghetti code. I did the rewrite in Go, and what used to take 13 seconds to generate now takes about 70 milliseconds—a 200x speedup. A lot of the speedup is due to how I refactored the logical structure of the code. For instance, the Python code had some crazy logic that generated HTML from Markdown, then parsed the generated HTML with lxml, munged the lxml DOM, and then reconverted back to HTML. That kind of logic is something I fixed with the rewrite, but could have also just fixed in the Python version. Anyway, since the blog code isn’t that interesting, I won’t dwell on it. I will point out a few minor changes though, in case I have errors in the new version.

There were a bunch of minor differences in how the Python library I was using parsed markdown compared to the Go library I’m using. I had to manually rewrite links that contained embedded parentheses. The code that handles em dashes also works differently. I fixed up all of my old blog hosts using a combination of manually modifying old posts and some scripts I wrote. I think I got most things right, but I’m sure I missed a few things.

Previously I was able to do syntax highlighting for code snippets server-side, using Pygments. The new version of the site does syntax highlighting using client-side Javascript, via highlight.js. Hopefully this isn’t too annoying.

I had to redo the RSS feed publishing logic. The good news is that I’m now using a real RSS library to generate RSS, instead of the crappy hand-written RSS generator I had before. This means the RSS generated is more likely to be well formed. The bad news is that if you consume this site via RSS, you may see a bunch of things republished to your feed, since some RSS readers will mark an item as “new” if its format changes in the RSS feed, even if the link hasn’t changed. There’s not a whole lot I can do about this, and I apologize in advance.