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] 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