Custom WEBrick FileHandler for stripping .html extension

This first performs the normal static file check at the exact
location. If no file is found, attempt the check again with an
".html" suffix.

See the following for base class search_file implementation:

https://github.com/ruby/ruby/blob/4607f95/lib/webrick/httpservlet/filehandler.rb#L363-L383
This commit is contained in:
Ryan Tomayko 2015-02-12 21:53:13 -05:00
parent 249249f76b
commit e99a9e5821
1 changed files with 14 additions and 1 deletions

View File

@ -40,7 +40,7 @@ module Jekyll
s.mount(
options['baseurl'],
WEBrick::HTTPServlet::FileHandler,
FileHandler,
destination,
file_handler_options
)
@ -131,6 +131,19 @@ module Jekyll
end
# Custom WEBrick FileHandler servlet for serving "/file.html" at "/file"
# when no exact match is found. This mirrors the behavior of GitHub Pages
# and many static web server configs.
require 'webrick'
class FileHandler < ::WEBrick::HTTPServlet::FileHandler
def search_file(req, res, basename)
if file = super
file
else
super(req, res, "#{basename}.html")
end
end
end
end
end
end