From 348417601b8201c78ebf72b5c41d54f8cb3b2fc7 Mon Sep 17 00:00:00 2001 From: 747 <747.neutron+ghub@gmail.com> Date: Tue, 29 Apr 2014 22:43:33 +0900 Subject: [PATCH 1/2] quick fix for finding eponymous parents --- .../sitemap/extensions/traversal.rb | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/middleman-core/lib/middleman-core/sitemap/extensions/traversal.rb b/middleman-core/lib/middleman-core/sitemap/extensions/traversal.rb index 78f8eb28..4e9aabee 100644 --- a/middleman-core/lib/middleman-core/sitemap/extensions/traversal.rb +++ b/middleman-core/lib/middleman-core/sitemap/extensions/traversal.rb @@ -9,16 +9,23 @@ module Middleman # @return [Middleman::Sitemap::Resource, nil] def parent parts = path.split('/') - parts.pop if path.include?(app.index_file) + tail = parts.pop + is_index = (tail == app.index_file) - return nil if parts.length < 1 + return nil if is_index && parts.length < 1 - parts.pop - parts << app.index_file + test_expr = parts.join('\\/') + # A makeshift for eponymous reverse-lookup + found = store.resources.find { |candidate| + candidate.path =~ %r!^#{test_expr}(?:\.[a-zA-Z0-9]+|\/)$! + } - parent_path = '/' + parts.join('/') - - store.find_resource_by_destination_path(parent_path) + if found + return found + else + parts.pop if is_index + return store.find_resource_by_destination_path("#{parts.join('/')}/#{app.index_file}") + end end # This resource's child resources From d1d3e8dba65a22bef736efde644f7ebd4aa8501d Mon Sep 17 00:00:00 2001 From: 747 <747.neutron+ghub@gmail.com> Date: Fri, 2 May 2014 05:53:59 +0900 Subject: [PATCH 2/2] add tests on eponymous parent traversal --- middleman-core/features/more-sitemap_traversal.feature | 10 ++++++++++ middleman-core/features/sitemap_traversal.feature | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/middleman-core/features/more-sitemap_traversal.feature b/middleman-core/features/more-sitemap_traversal.feature index 224c2b8a..f935fbf0 100644 --- a/middleman-core/features/more-sitemap_traversal.feature +++ b/middleman-core/features/more-sitemap_traversal.feature @@ -71,3 +71,13 @@ Feature: Step through sitemap as a tree (more) 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" + + Scenario: Child pages can see their parent and siblings too in named directory + Given the Server is running at "more-traversal-app" + When I go to "/directory-indexed/sibling" + Then I should see "Path: directory-indexed/sibling.html" + Then I should see "Parent: directory-indexed.html" + Then I should see "Sibling: directory-indexed/fake.html" + Then I should see "Sibling: directory-indexed/fake2.html" + Then I should see "Sibling: directory-indexed/sibling2.html" + Then I should see "Sibling: directory-indexed/sub2/index.html" diff --git a/middleman-core/features/sitemap_traversal.feature b/middleman-core/features/sitemap_traversal.feature index 828a2507..d2fe581c 100644 --- a/middleman-core/features/sitemap_traversal.feature +++ b/middleman-core/features/sitemap_traversal.feature @@ -71,3 +71,13 @@ Feature: Step through sitemap as a tree 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" + + Scenario: Child pages can see their parent and siblings too in named directory + Given the Server is running at "traversal-app" + When I go to "/directory-indexed/sibling.html" + Then I should see "Path: directory-indexed/sibling.html" + Then I should see "Parent: directory-indexed.html" + Then I should see "Sibling: directory-indexed/fake.html" + Then I should see "Sibling: directory-indexed/fake2.html" + Then I should see "Sibling: directory-indexed/sibling2.html" + Then I should see "Sibling: directory-indexed/sub2/index.html"