My Baked Blog
As you may (or may not) know, I am a really big fan of Dan Benjamin and his 5by5 podcasts. I was listening to this week’s Build and Analyze episode (with Marco Arment) and they were talking about Brent Simmons’ Plea for Baked Weblogs and Marco’s ideas of how to implement this. That really got me thinking. How cool would it be to write my own simple blogging engine?! And as I was thinking about it, it seemed like it could be done pretty easily, so I think I am going to try to do it myself (even if it is just for my own education and never gets used). This post will be a basic outline of all I think it would take to do it.
Since I know Python best, I’ll use that for most of the programming and found a Python version of Markdown. Other than that, I’ll use Dropbox to store all the posts so I can write and edit posts from my iPhone or iPad via the PlainText app (my current favorite text editor).
My basic idea is to write two shell (or Python?) scripts, called rebuild and rebuild_all. Rebuild will be a cron job that runs every minute. If there are any new text files ready to be posted, it will change them from Markdown to HTML, rebuild the home page, and rebuild the archive page (only the files that need to be rebuilt to accommodate a new post). Rebuild_all will be a cron job that runs once a day to go through and rebuild all HTML files on the entire website (which will allow it to catch any edits I make). Since all Markdown files will be stored in my Dropbox, I can edit any of them at any time from any device I want. I think this would be a very simple, but elegant solution.
Here is a listing of the basic tasks each script will do:
Script 1 - rebuild (every minute)
- Check /drafts folder in Dropbox for any file beginning with “zz” (my way of denoting a file ready to be published)
- Put that file in /posts/year/month/day? folder in Dropbox and remove “zz” from the name
- Add “/posts/year/month/day?/title” to a text file which will be the home page log file
- Run Python script 1 that uses Markdown and a template HTML file to build the static HTML file for that post and put it in the www folder
- Run Python script 2 that uses Markdown and a template HTML file to build the home page from the home page log file
- Run Python script 3 that updates the archive HTML file
Script 2 - rebuild_all (every day)
- Traverse all of /posts folder in Dropbox, and for each Markdown (txt) file run Python script 1
- Run Python script 2
That’s it. It seems like it should be simple enough - now I just need to find the time to try to do it!