From 3cbda0ee360d2676c35379306ac7e8f1fee58142 Mon Sep 17 00:00:00 2001 From: Tim Bates Date: Fri, 13 Jul 2012 10:57:05 +0930 Subject: [PATCH] Added strip_index_file option for configuring urls --- middleman-core/lib/middleman-core/application.rb | 6 +++++- middleman-core/lib/middleman-core/sitemap/resource.rb | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index 7a12cbfa..dcf9bf1e 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -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 diff --git a/middleman-core/lib/middleman-core/sitemap/resource.rb b/middleman-core/lib/middleman-core/sitemap/resource.rb index 481212f6..da8e8f84 100644 --- a/middleman-core/lib/middleman-core/sitemap/resource.rb +++ b/middleman-core/lib/middleman-core/sitemap/resource.rb @@ -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