this blog generates its pages by shell script, and it's been a bit of a challenge to make the engine portable, so generated content and the code itself can be run anywhere.
one way this is made easier is with the <base href="$path" /> tag, which tells the user agent to prepend every source and reference with $path. as I developed on Safari, everything worked.
then I asked for some friends to look at it, and it turned out that the base tag doesn't quite work like I'd hoped: you can't use a relative path as your base href, and firefox enforces this strictly.
there's two options for fixing this: the blog engine itself has to know where it lives on the server, so it can populate the base href correctly, making generated content less portable. alternately, the output generation could be smarter and append the relative base href to the beginning of every source and reference it sees, making the output code messier.
luckily, if you're ok with requiring your clients to support javascript (which I am), there's a third option. behold:
<script type="text/javascript">
document.write('<base href="' +
document.baseURI.substring(0, document.baseURI.lastIndexOf('/')) +
'<?= $blogroot ?>" />');
</script>
put that in the beginning of your <head> and it will emit the correct absolute base href at runtime.
thanks to Christian Hammond for the code and debugging help.
edited on thursday september 10th, 2009 at 22:38 at 11:58 :
as usual, this doesn't work everywhere. notably: Opera, IE, and Konqueror, all versions. I ask myself "do I care?" and respond "no."
edited on friday february 19th, 2010 at 21:38 at 11:58 :
this blog no longer uses this hack, because base hrefs were interfering with footnotes. were it up to me I would still use this. because it is great.