X-Git-Url: https://git.ralfj.de/web.git/blobdiff_plain/d3c771bb7374a6611cbd8e564f4e7bd4ea740660..089b119bd20febec1586a2c07e31007a41a6e211:/personal/_plugins/menu.rb diff --git a/personal/_plugins/menu.rb b/personal/_plugins/menu.rb index 48befa7..92eaa6a 100644 --- a/personal/_plugins/menu.rb +++ b/personal/_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