merge PR
This commit is contained in:
commit
1006739e98
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -6,16 +6,23 @@ module Middleman
|
|||
# @return [Middleman::Sitemap::Resource, nil]
|
||||
def parent
|
||||
parts = path.split('/')
|
||||
parts.pop if path.include?(app.config[:index_file])
|
||||
tail = parts.pop
|
||||
is_index = (tail == app.config[:index_file])
|
||||
|
||||
return nil if parts.length < 1
|
||||
return nil if is_index && parts.length < 1
|
||||
|
||||
parts.pop
|
||||
parts << app.config[:index_file]
|
||||
test_expr = parts.join('\\/')
|
||||
# eponymous reverse-lookup
|
||||
found = store.resources.find do |candidate|
|
||||
candidate.path =~ %r!^#{test_expr}(?:\.[a-zA-Z0-9]+|\/)$!
|
||||
end
|
||||
|
||||
parent_path = '/' + parts.join('/')
|
||||
|
||||
store.find_resource_by_destination_path(parent_path)
|
||||
if found
|
||||
found
|
||||
else
|
||||
parts.pop if is_index
|
||||
store.find_resource_by_destination_path("#{parts.join('/')}/#{app.config[:index_file]}")
|
||||
end
|
||||
end
|
||||
|
||||
# This resource's child resources
|
||||
|
|
Loading…
Reference in a new issue