I’ve been rewriting my static site in Webby, a Ruby static website management system. Hopefully, if it all works, you won’t notice. The only way you’ll notice is if you peek under the hood. I’m using “Options +MultiViews” in Apache to do URL rewriting, and there’ll be more about that later.

Using Webby is pretty easy: webby site-name makes a new folder. Inside, there’s a content/ folder where you can put your content. These are .txt files which contain some YAML to include the title, what filters it runs through (ERb and Textile for instance) and what layout it uses.

It comes with Rake tasks to build and deploy. Here’s how I’m using mine. The basic procedure is rake build and then rake deploy to SCP or rsync it to your server (I use SCP). I’ve introduced another step - rake validate.

What does the validate task do? Well, the validation I’m doing is using oNVDL, which is a Java tool to validate XML. I’m using James Clark’s XHTML modular schema, specifically xhtml-strict.rng. There is a downside with this approach, and one I’ll probably fix soon - that is, if you use a mixture of HTML 4 and XHTML, or you use different types of XHTML - either 1.0 and 1.1, or Strict and Transitional, or even the new modular DTDs that the W3C have put out for SVG and RDFa. The reason I used the RELAX NG schema is because I had it there and was in a hurry, I knew how to use oNVDL and I’d used the modular RNG schemas before.

The Rake task is quite simple:

desc 'validate XHTML'
task :validate do
Dir.glob('output/**/*.html').each do |f|
print "validating " + f + "\n"
sh "java -jar /Applications/oxygen/lib/onvdl.jar /Users/tommorris/bin/xhtmlrng/xhtml-strict.rng " + f
print "\n"
end
end

This will iterate through your output folder (the place where built markup goes) and validates each one against the schema. It should also print the result to your screen. You’ll see nothing if it’s all good, but you’ll get errors like this otherwise: /Users/tommorris/code/HTML/test/output/profiles/nsfw.html:3:71: error: attribute “lang” not allowed at this point; ignored

The nice thing is that the Java process exits with status 1 if there are problems, meaning the rake task itself is aborted. You can then fix one error at a time. And you can also make your deployment (or repository commit) dependent on the whole site validating. Hey, it’s compile-time error checking for XHTML! I’m sure some people are now furious since HTML is Not A Programming Language, but for me, this is important. I want my computer to tell me when things go wrong, and prevent me from sending invalid markup out on to the web. I’m sure one could even replace the validator with a stricter one that does some basic accessibility tests - and it’d be neat if we could add similar tests for CSS and so on.

Once you validate all the markup as XHTML, you probably want to then get Apache to serve the files as application/xhtml+xml, but not do so when Internet Explorer comes knocking on your door, since Internet Explorer is so utterly shite that it can’t read XHTML properly. Adding the following to your .htaccess file does exactly that:

RewriteEngine on
AddType application/xhtml+xml html
RewriteCond %{HTTP_USER_AGENT} ((.*MSIE.*)|(Lynx.*))
RewriteRule .* - [T=text/html]

This will serve all your .html files as XHTML, unless Internet Explorer or Lynx is being used, in which case it should get text/html instead. XHTML 1.0 can be served as application/xhtml+xml or text/html - but if you are using XHTML 1.1, or maybe the custom XHTML+RDFa DTD, then the validator and specification says you should be serving it as application/xhtml+xml. It’s probably okay if you still allow people using retarded browsers like Internet Explorer get your XHTML as text/html though.

By the way, one last thing - I mentioned earlier in passing ‘repository commit’. If you are using Git to manage your Webby sites (and frankly, you should be, since Git is made of win), you should not check your output directory in. Just add output/* to .gitignore. I’d highly recommend keeping your static site in version control. It’s very useful to be able to roll your site back, or get a list of all the changes you made to the template or the CSS… 