Add trailing_slash option for prettier urls

"set :trailing_slash, false" will cause resource urls that match the
index_file to have the trailing slash stripped off the directory URL,
e.g. instead of "/dir/index.html" becoming "/dir/" it will be "/dir"
This commit is contained in:
Tim Bates 2012-07-12 12:03:33 +09:30
parent 5c9a5c9849
commit 692aa10c8b
2 changed files with 5 additions and 1 deletions

View file

@ -93,6 +93,10 @@ module Middleman
# @return [String]
set :index_file, "index.html"
# Whether to include a trailing slash on links to directory indexes
# @return [Boolean]
set :trailing_slash, true
# Location of javascripts within source.
# @return [String]
set :js_dir, "javascripts"

View file

@ -142,7 +142,7 @@ module Middleman
# @return [String]
def url
File.join(app.respond_to?(:http_prefix) ? app.http_prefix : '/',
destination_path.sub(/\/#{Regexp.escape(app.index_file)}$/, '/'))
destination_path.sub(/\/#{Regexp.escape(app.index_file)}$/, app.trailing_slash ? '/' : ''))
end
end
end