We(might)Blog

Completely disillusioned by all the various blogging tools out there, I've been playing with a new format I just came up with.

It works simply by using plain text files, with header definitions at the top in a similar format to those doled out over HTTP:

title: Ello
class: section
description: Some descriptive blah
tags: you're it!

Content goes here, in <em>html</em>.  Vaguely toyed with the idea of using wiki syntax but that's a shelveable option.

We set a file extension to treat as source files (a la Blosxom, RIP), and set this extension to be handled by php. Then we set auto_prepend_file to our handler, like so:

DirectoryIndex index.src 

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !\.src$
RewriteRule (.*) $1.src

<FilesMatch "\.src$">
	SetHandler application/x-httpd-php
	php_value auto_prepend_file /path/to/handler.php
</FilesMatch>

(To prevent PHP from actually running the source file, the handler kills the script at the end of the procedure).

Our handler parses the file (simple), outputs it, and having flushed the output sticks the tags and description in an SQLite database, and caches the output in a RAM-residing filesystem (e.g. /tmp). Subsequent requests for the same file make a cache hit (unless the source file is newer than the cache), whereupon the cached file is dumped out and a Last-modified header is sent giving the mtime of the cache file. Subsequent requests from the same client will then of course push out a 304.

Ah”, but you say, “agressive cacheing is all well and good, but what about sections with dynamic content? We always need to hit the database on every visit on some pages...

The header definitions in the individual entries (or set globally in .htaccess as below) take care of that. By cacheing our output in a directory structure that mimics the public-facing filesystem (and by saying goodbye to query strings - boo-hoo!), we can tell the handler what cache records to destroy when our source file is modified with a bit of glob syntax:

SetEnv src_mods_affect ["blog/index", "blog/search/*"]

(That parenthesised array syntax is JSON, which of course PHP can parse all by itself.)

I will naturally stick the source in a repository somewhere as soon as I've ironed out any security issues. Before that, I'll do some more writing! I hate bloaty code soooo much (hate! hate! hate!) I've not managed to keep a blog since the dark days of sameindeath.com (also RIP).

To get the idea, view this page's blog source and you'll see just how handy it is already, after an afternoon's scripting am using Drupal now. Never use development stuff in production, does your nut in.

Who? What? Huh?

If you just got here and am wondering who I am, head on over to the web section to see some examples of my work, or just go ahead and contact me if that's what you came for.