⇐ Previous | Next ⇒

Serving Static Nanoc Site Files With Ruby 1.8

Post created 2014-03-14 16:56 by Gabe Koss.

This blog is written using a static site generator called Nanoc. Nanoc is a great tool to generate fast and stable static sites (like this one!).

I recently created a small Nanoc based wiki type site for a friend. Unfortunately due to a legacy laptop she can only run Ruby 1.8 so I was trying to figure out a good way to serve the files.

I knew that Sinatra could be still be installed on 1.8 without too much trouble but when i set the nanoc output/ dir as the Sintra public dir I had to access the pages by manually adding an index.html extension.

The Nanoc generated file tree looks something like this.


I assumed I could do this simply enough with Sinatra and this is what I came up with.

#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'

class Ruby18App < Sinatra::Base
  set :public_folder, Proc.new { File.join(root, "output") }

  get "*" do
    unless request.path.split('/').last == "index.html"
      new_path = File.join(request.path, "index.html")
      redirect to(new_path)
  run! if app_file == $0

Note that I had to redirect paths to take into account the index.html files.

comments powered by Disqus