dirindex - simple static HTML index generator

I've been hosting static websites on Amazon's S3 service for a few months now, and generally been very happy with the results. One drawback to this approach at present, though, is that there are no directory listings: the S3 web server will either serve up an existing file, or an error.

Enter dirindex. This little Ruby script generates an HTML directory listing, much like those from Apache or other 'traditional' webservers for a specific directory.

In my case, this site is generated offline using Jekyll, then uploaded to S3 as needed. A few lines of shell script invoke dirindex on each directory which lacks an index:

  1. #!/bin/sh
  3. jekyll
  4. cd _site
  5. for i in `find . -type d|sed -e 's/^\.\///'`
  6. do
  7. if [ ! -e $i/index.html ]
  8.     then
  9.     dirindex.rb $i > $i/.tmp.index.html && mv $i/.tmp.index.html $i/index.html
  10. fi
  11. done
  12. mksitemap.pl www.deadnode.org > sitemap.xml
  13. s3cmd sync -P -c ~/.js-s3cfg ./ s3://www.deadnode.org/

The idea here is that line 5 iterates through all directories within the site (stripping the leading './' find prepends), line 7 checks if an index.html file already exists there, and if not line 9 creates one in a temporary file then moves it into place. (Since dirindex skips all filenames starting '.', this prevents index files listing themselves.)

Line 12 generates the sitemap XML file using a similar utility which I intend to release here soon.

Download dirindex.rb - please send any requests/patches/bug reports/donations to me, james@deadnode.org.