Skip to content

Instantly share code, notes, and snippets.

@scottwater
Created September 20, 2010 00:40
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save scottwater/587274 to your computer and use it in GitHub Desktop.
Save scottwater/587274 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