link directly to iris-project.org
[web.git] / ralf / _plugins / menu.rb
index 48befa744554a401219d35667b016724eae50881..92eaa6a48cba06124d5f79ac854a9d1c3883307a 100644 (file)
@@ -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