Sunday 25th December 2011

Vorax (the site)

This version of my new web site has recently been re-written to make use of plain text input files. I decided on plain text as input because I want to be able to edit my site with any old text editor. I like to create and edit pages in my IDE or in vim via the console.

The plain text is saved to a content folder and I write top level menu entries into a simple text configuration file. When you browse the site, I read the URL and figure out which page you have requested. The site, then checks it's cache for pre-rendered content and serves it up if it has some, otherwise it runs the text content through PHP Markdown Extra (a tool based on markdown but with a few extra features). The product of this process is standards adherent HTML which is then promptly cached so as to save the server effort when others ask for the same page.

I've also modified PHP Markdown Extra to call Pygments with the contents of code blocks when it finds them. This means that any plain text code I have in my content can be rendered in full syntax highlighted glory (also cached for speed). Here's an example of some nice syntax highlighted code...

    /**
     * This is a block comment
     */
    class Bob() {

        private String data = "the default data";

        public Bob() {
        }

        public String getData() {
            // get some
            return this.data;
        }

        public void setData(String data) {
            // set some
            this.data = data;
        }

    }

A further word about the cache... it's nothing like Drupal's cache (a pet hate of mine). The cache is automatically re-calculated if plain text content is newer than it's related cache entry, i.e. if you change the plain text the cache for that page gets automatically rebuilt without you having to do anything, no special scheduled jobs, no pain when you're programming. Also, there is one boolean setting called cache_enabled which when set to false completely disables the cache.

Using plain text as the content guarantees that you keep style and content separate, subsequently, I've got quite a nice little powerful template system for style and page layout. The site ships with a default template which can be overridden in part or totally to provide a page layout any shape or size you want and CSS any way you like.