module MenuFilter
def menu(input, displayurl)
def create_menu(pages, base, displayurl)
+ # URLs in `base`, `displayurl`, `cururl` are normalized to remove trailing slashes. This is to be able to distinguish the root of a folder from its children by the number of slashes in the URL.
+ # We need this to treat the root of a folder as a direct child of the parent folder, whereas pages within a subfolder are of course grandchildren.
result = Array.new
for page in pages
- cururl = page['url'].sub('/index.html', '')
+ cururl = page['url'].chomp('/')
+ # Test if this page is a non-hidden *direct* child of `base`
if cururl.start_with?(base) and cururl.count('/') == base.count('/') and (not page['hide'])
# figure out CSS class
if cururl == displayurl
end
# store menu node
result.push(menu_node)
+ else
+ #print "Not adding: cur=", cururl, ", base=", base, ", hide=", page['hide'], "\n"
end
end
# sort the result before returning it
result.sort_by { |page| [page['sort'], page['url']] }
end
- create_menu(input, "", displayurl.sub('/index.html', ''))
+ create_menu(input, "", displayurl.chomp('/'))
end
end
end