lib/nanoc3/base/source_data/site.rb in nanoc3-3.2.0a4 vs lib/nanoc3/base/source_data/site.rb in nanoc3-3.2.0b1

- old
+ new

@@ -177,14 +177,25 @@ # manually; it will be called when appropriate. # # @return [void] def setup_child_parent_links teardown_child_parent_links - @items.each do |item| + + items = @items.sort_by { |i| i.identifier } + items.each_with_index do |item, index| # Get parent + next if index == 0 parent_identifier = item.identifier.sub(/[^\/]+\/$/, '') - parent = @items.find { |p| p.identifier == parent_identifier } - next if parent.nil? or item.identifier == '/' + parent = nil + (0..index-1).reverse_each do |candidate_index| + candidate = items[candidate_index] + if candidate.identifier == parent_identifier + parent = candidate + elsif candidate.identifier[0..parent_identifier.size-1] != parent_identifier + break + end + end + next if parent.nil? # Link item.parent = parent parent.children << item end