Over the last few weekends I've been migrating to a new home-built CMS. The new CMS is finally something I can be proud of function wise, and because it doesn't use and fancy SQL databases I know it will be more easily maintainable and much more search friendly. Counting this one, that makes four different CMS's I've gone through for this site and its predecessor. I've used 100% static HTML files, dynamic PHP pages that relied on SQL databases, and a 100% web form based system, none of which I was happy with. They were all too complicated to maintain, or just felt wrong to use for just a simple blog. I wanted something functional, and elegant.
The new CMS uses a remote Git repo to save all changes, and clones that repo into the web root. This article helped me get that set up, and I've referred back to it so often that it shows up first in my Safari search suggestions.
The CMS is actually just a set of mostly static pages that pull their data from JSON files. The JSON files are generated by a Python script on my local machine before being committed to the repository clone on my Mac and finally pushed to the server.
Writing the articles is the easiest part, as it should be. It's really simple; write a Markdown file and put five lines of metadata at the top: title, author, slug (optional), tags, and status. The status tells the Python script whether the article is a draft meant for previewing, or a ready-to-publish article. That's it. Run the Python script, look at the preview, change the status to "publish", commit the changes and publish to the server. The rest is taken care of by PHP snippets, Python scripts, and Git's magic.
When I started out with this refactor, I had my sights set on using PHP for everything, like I had before. I'm no expert in PHP (I've probably written less than 2000 lines of it ever) but I don't particularly like it as a language, so I went with Python. I hadn't written Python in over a year, but it was easy enough to relearn, and over the time I've spent rewriting the CMS, I've fallen for Python as my preferred scripting language. In fact, I've come up with a project using Python's cool feature to integrate with C, but more on that later.
As for the scripts and the PHP template pages, I might clean them up for GitHub some day (they're still a little rough around the edges, and there's no current way to update an article automatically) but once a few bugs are worked out and features added, I'll try to get it up there.
Thanks to Marco Tabini for his articles on Louis and his static-file website articles, and thanks to Marco Arment for his method of generating previews and using Dropbox sync. I wish I could have built a system like his CMS SecondCrack but sadly my web host doesn't allow Dropbox to run on the server. And finally thanks to Abhijit Menon-Sen for his awesome explanation of how to deploy a website using Git.