quick fix for finding eponymous parents

This commit is contained in:
747 2014-04-29 22:43:33 +09:00
parent 299263c7e5
commit 348417601b

View file

@ -9,16 +9,23 @@ module Middleman
# @return [Middleman::Sitemap::Resource, nil] # @return [Middleman::Sitemap::Resource, nil]
def parent def parent
parts = path.split('/') 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 test_expr = parts.join('\\/')
parts << app.index_file # A makeshift for eponymous reverse-lookup
found = store.resources.find { |candidate|
candidate.path =~ %r!^#{test_expr}(?:\.[a-zA-Z0-9]+|\/)$!
}
parent_path = '/' + parts.join('/') if found
return found
store.find_resource_by_destination_path(parent_path) else
parts.pop if is_index
return store.find_resource_by_destination_path("#{parts.join('/')}/#{app.index_file}")
end
end end
# This resource's child resources # This resource's child resources