Blog tech
I've spent som time lately rebuilding this blog, because that's a useful thing to be spending my free time on. Maybe. Anyway, before starting I decided that I wanted the blog to be one of them fancy static things that Blogger made popular a while back.
I had a look at the various available tools for such blogs, but since they're not made by me they're not perfect – I obviously needed to write my own. A colleague said something like "shouldn't take more than 40 lines of Python", and if that isn't a challenge I don't know what is!
Turns out that I wanted things to be a bit more complicated than 40 lines, but the current version of the generator script is about 160 lines, so it's not so bad. Good thing there are nice libs like Genshi, feedgen and Markdown available for free that do the grunt work! The old blog contained a bunch of posts that I transplanted into the new system. It's useful to have a few posts to test with, after all. Then I copied and pasted various bits of CSS and HTML from the old system into a theme in the new one, and here we are.
The system is laid up like this:
- generate.py
- publish.sh
-
posts
-
[one dir per post]
- meta.json
-
static
- per-post files like images etc
- something.md
-
[one dir per post]
- static
-
themes
-
[one dir per theme]
- index.html
- post.html
-
static
- per-theme files like images, CSS, etc
-
[one dir per theme]
-
output
- lots of generated files and dirs
generate.py scans the posts dir and makes a list of posts. Each post is rendered using the theme's post.html template and put into the output/posts dir. When all the posts are finished, the main index.html is generated, with a list of the most recent posts.
Each post has a meta.js file that specifies the post's title, date, etc. It also specifies which file contains the content of the post, which is Markdown-converted into HTML that is wrapped inside the template. The reason for not just having a content.md hardcoded is that I'd like to be able to search locally for the files and not have all matching filenames be identical, and that given a different suffix something other than Markdown could be used, ReST or whatnot.
So that's basically it. Some day I might clean the code up a bit and extract the content into a separate location and make the engine public, but since there are already a gazillion things just like this already out there I don't know if I'll bother. Mine's good for me, and that's good enough.
Future additions I might get to is to allow each post to specify which theme to use. Custom CSS per post is already possible, although I don't use it yet.