Added strip_index_file option for configuring urls

This commit is contained in:
Tim Bates 2012-07-13 10:57:05 +09:30
parent 2117cbac79
commit 3cbda0ee36
2 changed files with 11 additions and 3 deletions

View file

@ -93,7 +93,11 @@ module Middleman
# @return [String]
set :index_file, "index.html"
# Whether to include a trailing slash on links to directory indexes
# Whether to strip the index file name off links to directory indexes
# @return [Boolean]
set :strip_index_file, true
# Whether to include a trailing slash when stripping the index file
# @return [Boolean]
set :trailing_slash, true

View file

@ -141,8 +141,12 @@ module Middleman
# just foo. Best for linking.
# @return [String]
def url
File.join(app.respond_to?(:http_prefix) ? app.http_prefix : '/',
destination_path.sub(/\/#{Regexp.escape(app.index_file)}$/, app.trailing_slash ? '/' : ''))
url_path = destination_path
if app.strip_index_file
url_path = url_path.sub(/\/#{Regexp.escape(app.index_file)}$/,
app.trailing_slash ? '/' : '')
end
File.join(app.respond_to?(:http_prefix) ? app.http_prefix : '/', url_path)
end
end
end