Skip to content
Browse files

directory index auto-ignores files already named index

  • Loading branch information...
1 parent ca2666c commit 12a00e3811ec76f14900383de485034dab2bc79d @tdreyno tdreyno committed Aug 2, 2011
View
2 features/directory_index.feature
@@ -6,6 +6,8 @@ Feature: Directory Index
Then "needs_index/index.html" should exist at "indexable-app" and include "Indexable"
Then "a_folder/needs_index/index.html" should exist at "indexable-app" and include "Indexable"
Then "leave_me_alone.html" should exist at "indexable-app" and include "Stay away"
+ Then "regular/index.html" should exist at "indexable-app" and include "Regular"
+ Then "regular/index/index.html" should not exist at "indexable-app"
Then "needs_index.html" should not exist at "indexable-app"
Then "a_folder/needs_index.html" should not exist at "indexable-app"
Then "leave_me_alone/index.html" should not exist at "indexable-app"
View
1 fixtures/indexable-app/source/regular/index.html
@@ -0,0 +1 @@
+Regular
View
12 lib/middleman/features/directory_indexes.rb
@@ -12,6 +12,8 @@ def registered(app)
if app.settings.ignored_directory_indexes.include?(request_path)
false
+ elsif request_path =~ /#{new_index_path}$/
+ false
else
[
destination.gsub(/#{index_ext.gsub(".", "\\.")}$/, new_index_path),
@@ -21,16 +23,20 @@ def registered(app)
end
app.before do
- indexed_path = request.path_info.gsub(/\/$/, "") + File.extname(app.settings.index_file)
+ indexed_path = request.path_info.gsub(/\/$/, "") + "/" + app.settings.index_file
+ indexed_exists = resolve_template(indexed_path, :raise_exceptions => false)
+
+ extensioned_path = request.path_info.gsub(/\/$/, "") + File.extname(app.settings.index_file)
+ is_ingored = settings.ignored_directory_indexes.include?(extensioned_path)
- if !settings.ignored_directory_indexes.include?(indexed_path)
+ if !indexed_exists && !is_ingored
parts = request.path_info.split("/")
last_part = parts.last
last_part_ext = File.extname(last_part)
if last_part_ext.blank?
# This is a folder, redirect to index
- request.path_info = indexed_path
+ request.path_info = extensioned_path
end
end
end

0 comments on commit 12a00e3

Please sign in to comment.
Something went wrong with that request. Please try again.