X-Git-Url: https://git.ralfj.de/web.git/blobdiff_plain/c3f35ab1622ecb792dba0ece727f148abf6018fb..6196ef45e7f7e313168122b859b872ae2892fa94:/ralf/_plugins/menu.rb diff --git a/ralf/_plugins/menu.rb b/ralf/_plugins/menu.rb index 48befa7..92eaa6a 100644 --- a/ralf/_plugins/menu.rb +++ b/ralf/_plugins/menu.rb @@ -2,9 +2,12 @@ module Jekyll 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 @@ -36,13 +39,15 @@ module Jekyll 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