quick fix for finding eponymous parents
This commit is contained in:
parent
299263c7e5
commit
348417601b
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue