#parent_helper(child_path, max_recursion) ⇒ Object

# File 'middleman-core/lib/middleman-core/sitemap/extensions/traversal.rb', line 22defparent_helper(child_path,max_recursion)# What is the configured format for index pages.
index_file=@app.config[:index_file]parts=child_path.split('/')# Reduce the path by the current page to get the parent level path.
current_page=parts.pop# Does the current page has the name of an index file?
is_index=current_page==index_file# Is the `current_page` in the traversal root?
# Note: `traversal_root` is `/` for non localized pages and `/[lang]/` for
# localized pages.
at_traversal_root=!(child_path=~/^#{traversal_root}#{current_page}$/).nil?# Check that we have any path parts left after the pop because if we
# don't, `current_page` is either root or another file under root.
# Also, if we are `at_traversal_root`, we consider this root.
ifparts.empty?||at_traversal_root# If this `is_index`, the `current_page` is root and there is no parent.
returnnilifis_index# `current_page` must be a page under root, let's return the root
# index page of the `traversal_root` (`/` or `/[lang]/`).
return@store.by_path("#{traversal_root}#{index_file}")end# Get the index file for the parent path parts, e.g.: `/blog/index.html`
# for `/blog/`.
index_by_parts=procdo|subparts|found=@store.by_destination_path("#{subparts.join('/')}/#{index_file}")returnfoundunlessfound.nil?end# Get a file that has the name of the parent path parts e.g.:
# `/blog.html` for `/blog/`.
file_by_parts=procdo|subparts|test_expr=Regexp.escape(subparts.join('/'))# eponymous reverse-lookup
found=@store.resources.finddo|candidate|candidate.path=~%r{^#{test_expr}(?:\.[a-zA-Z0-9]+|\/)$}endreturnfoundunlessfound.nil?end# Try to find a file matching the parent path name and return it.
# E.g. `parts == ['en', 'blog']`, we try to find: `/en/blog.html`
file_by_parts.call(parts)# Try to find an non-localized parent instead if `traversal_root`
# indicates the path is localized and there are still more parts
# remaining, and return it.
# E.g. `parts == ['en', 'blog']`, we try to find: `/blog.html`
file_by_parts.call(parts[1..-1])iftraversal_root!='/'&&parts.length>1# Now let's drop the last part of the path to try to find an index
# file in the path above `current_page`'s path and return it.
# E.g. `parts == ['en', 'blog']`, we try to find: `/en/index.html`
parts.popifis_indexindex_by_parts.call(parts)# Lastly, check for an non-localized index index file in the path
# above `current_page`'s path and return it.
# E.g. `parts == ['en', 'blog']`, we try to find: `/index.html`
index_by_parts.call(parts[1..-1]||'')iftraversal_root=="#{parts.first}/"returnparent_helper(parts.join('/'),max_recursion-1)if!parts.empty?&&max_recursion.positive?nilend