Skip to content

Instantly share code, notes, and snippets.

@evs
Forked from scottwater/config.ru
Created December 15, 2010 07:45
Show Gist options
  • Save evs/741746 to your computer and use it in GitHub Desktop.
Save evs/741746 to your computer and use it in GitHub Desktop.
require 'sj'
run SinatraJekyll
require 'sinatra/base'
class SinatraJekyll < Sinatra::Base
get /.+/ do
send_sinatra_file(request.path) {404}
end
not_found do
send_sinatra_file('404.html') {"Sorry, I cannot find #{request.path}"}
end
def send_sinatra_file(path, &missing_file_block)
file_path = File.join(File.dirname(__FILE__), '_site', path)
file_path = File.join(file_path, 'index.html') unless file_path =~ /\.[a-z]+$/i
File.exist?(file_path) ? send_file(file_path) : missing_file_block.call
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment