diff --git a/features/sitemap_traversal.features b/features/sitemap_traversal.features index b9403863..73cda82c 100644 --- a/features/sitemap_traversal.features +++ b/features/sitemap_traversal.features @@ -53,4 +53,21 @@ Feature: Step through sitemap as a tree Scenario: Proxied page has source_file Given the Server is running at "traversal-app" When I go to "/sub/fake.html" - Then I should see "Source: source/proxied.html.erb" \ No newline at end of file + Then I should see "Source: source/proxied.html.erb" + + Scenario: Child pages have data + Given the Server is running at "traversal-app" + When I go to "/directory-indexed" + Then I should see "Title of Sibling One" + Then I should see "Title of Sibling Two" + + Scenario: When directory_index extension is active, child pages are found in named directory + Given the Server is running at "traversal-app" + When I go to "/directory-indexed" + Then I should see "Parent: index.html" + Then I should see "Child: directory-indexed/fake.html" + Then I should see "Child: directory-indexed/fake2.html" + Then I should see "Child: directory-indexed/sibling.html" + Then I should see "Child: directory-indexed/sibling2.html" + Then I should see "Child: directory-indexed/sub2/index.html" + Then I should see "Sibling: root.html" diff --git a/fixtures/traversal-app/config.rb b/fixtures/traversal-app/config.rb index f0da15f0..6d1883c4 100644 --- a/fixtures/traversal-app/config.rb +++ b/fixtures/traversal-app/config.rb @@ -1,2 +1,7 @@ +activate :directory_indexes + page "/sub/fake.html", :proxy => "/proxied.html", :ignore => true -page "/sub/fake2.html", :proxy => "/proxied.html", :ignore => true \ No newline at end of file +page "/sub/fake2.html", :proxy => "/proxied.html", :ignore => true + +page "/directory-indexed/fake.html", :proxy => "/proxied.html", :ignore => true +page "/directory-indexed/fake2.html", :proxy => "/proxied.html", :ignore => true \ No newline at end of file diff --git a/fixtures/traversal-app/source/directory-indexed.html.erb b/fixtures/traversal-app/source/directory-indexed.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/fixtures/traversal-app/source/directory-indexed/sibling.html.erb b/fixtures/traversal-app/source/directory-indexed/sibling.html.erb new file mode 100644 index 00000000..03491028 --- /dev/null +++ b/fixtures/traversal-app/source/directory-indexed/sibling.html.erb @@ -0,0 +1,3 @@ +--- +title: Title of Sibling One +--- \ No newline at end of file diff --git a/fixtures/traversal-app/source/directory-indexed/sibling2.html.erb b/fixtures/traversal-app/source/directory-indexed/sibling2.html.erb new file mode 100644 index 00000000..350f799d --- /dev/null +++ b/fixtures/traversal-app/source/directory-indexed/sibling2.html.erb @@ -0,0 +1,3 @@ +--- +title: Title of Sibling Two +--- \ No newline at end of file diff --git a/fixtures/traversal-app/source/directory-indexed/sub2/index.html.erb b/fixtures/traversal-app/source/directory-indexed/sub2/index.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/fixtures/traversal-app/source/directory-indexed/sub3/deep.html.erb b/fixtures/traversal-app/source/directory-indexed/sub3/deep.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/fixtures/traversal-app/source/layout.erb b/fixtures/traversal-app/source/layout.erb index 9aa1ac16..c6daca12 100644 --- a/fixtures/traversal-app/source/layout.erb +++ b/fixtures/traversal-app/source/layout.erb @@ -10,4 +10,10 @@ Source: <%= current_page.source_file.sub(root + "/", "") %> <% current_page.siblings.each do |p| %> Sibling: <%= p.path %> +<% end %> + +<% current_page.children.each do |p| %> + <% if p.data %> + Data: <%= p.data %> + <% end %> <% end %> \ No newline at end of file diff --git a/lib/middleman/sitemap/page.rb b/lib/middleman/sitemap/page.rb index e258ff21..4feb448c 100644 --- a/lib/middleman/sitemap/page.rb +++ b/lib/middleman/sitemap/page.rb @@ -99,9 +99,31 @@ module Middleman::Sitemap end end + + def directory_index? - path.include?(app.index_file) || path =~ /\/$/ + path.include?(app.index_file) || path =~ /\/$/ || eponymous_directory? end + + def eponymous_directory? + !!Dir.exists?(File.join(app.source_dir, eponymous_directory_path)) + end + + def eponymous_directory_path + path.sub('.html', '/').sub(/\/$/, "") + "/" + end + + def relative_path + source_file.sub(app.source_dir, '') + end + + def data + data, content = app.frontmatter.data(relative_path) + data || nil + end + + + def parent parts = path.split("/") @@ -126,17 +148,22 @@ module Middleman::Sitemap def children return [] unless directory_index? - - base_path = path.sub("#{app.index_file}", "") - prefix = /^#{base_path.sub("/", "\\/")}/ + if eponymous_directory? + base_path = eponymous_directory_path + prefix = /^#{base_path.sub("/", "\\/")}/ + else + base_path = path.sub("#{app.index_file}", "") + prefix = /^#{base_path.sub("/", "\\/")}/ + end + store.all_paths.select do |sub_path| sub_path =~ prefix end.select do |sub_path| path != sub_path end.select do |sub_path| - relative_path = sub_path.sub(prefix, "") - parts = relative_path.split("/") + inner_path = sub_path.sub(prefix, "") + parts = inner_path.split("/") if parts.length == 1 true elsif parts.length == 2