From 829d4882357a14e711a16e6791b9b1f7c1fa742e Mon Sep 17 00:00:00 2001
From: Tom Wiesing <tkw01536@gmail.com>
Date: Mon, 5 Jun 2017 14:07:46 +0200
Subject: [PATCH] Optimize the menu a lot

---
 _includes/header.html         |  8 -----
 _includes/menu_sub.html       | 57 ++++++++---------------------------
 _includes/print_number.liquid | 10 ------
 3 files changed, 13 insertions(+), 62 deletions(-)
 delete mode 100644 _includes/print_number.liquid

diff --git a/_includes/header.html b/_includes/header.html
index 219afba..551f8b4 100644
--- a/_includes/header.html
+++ b/_includes/header.html
@@ -22,14 +22,6 @@
       <a href="{{ site.baseurl }}/"><img src="{{ site.baseurl }}/public/kwarc_logo.svg" width="180px" height="180px"></a>
     </div>
   </li>
-  {% capture page_priors %}
-    {% for page in site.pages %}
-      {% assign value = page.menu_order %}
-      {% include print_number.liquid %},
-    {% endfor %}
-  {% endcapture %}
-  
-  {% assign page_priors = page_priors | normalize_whitespace | replace: " ", "" | split:"," | uniq | sort | join: "," | append: "," %}
   
   {% for item in site.menu | sort:"menu_order %}
     {% if item.folder %}
diff --git a/_includes/menu_sub.html b/_includes/menu_sub.html
index a5e0c3e..b4d7ef7 100644
--- a/_includes/menu_sub.html
+++ b/_includes/menu_sub.html
@@ -1,6 +1,5 @@
 {% comment %}
   This page creates a submenu item. It expects an appropriate `item` as argument. 
-  Furthermore, it requires the page_priors global variable
 {% endcomment %}
 
 {% unless item.menu_hidden %}
@@ -18,22 +17,18 @@
     {% assign menu_active = true %}
   {% endif %}
   
-  <!-- find all our priorities and also check for activity -->
-  {% capture priors %}
-    {{ page_priors }}
+  <!-- check if we are in the current oder -->
     {% for item in item.items %}
-      {% unless item.menu_page %}
-        {% unless item.external_page %}
-          {% if item.url == page.url %}
-            {% assign menu_active = true %}
-          {% endif %}
+        {% unless item.menu_page %}
+            {% unless item.external_page %}
+                {% if item.url == page.url %}
+                    {% assign menu_active = true %}
+                {% endif %}
+            {% endunless %}
         {% endunless %}
-      {% endunless %}  
-      {% assign value = item.menu_order %}
-      {% include print_number.liquid %},
     {% endfor %}
-  {% endcapture %}
-  {% assign priors = priors | normalize_whitespace | replace: " ", "" | split:"," | uniq | sort %}
+    
+  {% assign pages = site.pages | sort: "menu_order"%}
   
   <!-- Find the current folder -->
   {% assign item_folder = item.folder %}
@@ -50,21 +45,9 @@
         </a>
         <div class="collapsible-body">
           <ul>
-            <!-- Start by iteratig over the priorities -->
-            {% for p in priors %}
-              
               <!-- If we have folders, iterate over them -->
               {% if item.folder %}
-                {% for item in site.pages %}
-                
-                  <!-- read item priority -->
-                  {% assign value = item.menu_order %}
-                  {% capture ip %}{% include print_number.liquid %}{% endcapture %}
-                  {% assign ip = ip | normalize_whitespace | replace: " ", "" %}
-                  
-                  <!-- pick all the ones with the current priority -->
-                  {% if ip == p %}
-                    
+                {% for item in pages %}
                     <!-- get the current page -->
                     {% assign sub_parts = item.url | split: '/' %}
                     {% assign sub_url = sub_parts | last %}
@@ -74,30 +57,16 @@
                     {% if sub_folder == item_folder %}
                       {% include menu_single.html %}
                     {% endif %}
-                    
-                  {% endif %}
-                  
                 {% endfor %}
               {% endif %}
               
               <!-- if we have items, iterate over them -->
               {% if item.items %}
-                {% for item in item.items %}
-                  <!-- read item priority -->
-                  {% assign value = item.menu_order %}
-                  {% capture ip %}{% include print_number.liquid %}{% endcapture %}
-                  {% assign ip = ip | normalize_whitespace | replace: " ", "" %}
-                  
-                  <!-- pick all the ones with the current priority -->
-                  {% if ip == p %}
-                  
-                    {% include menu_single.html %}
-                    
-                  {% endif %}
+                {% assign sitems = item.items | sort: "menu_order"%}
+                {% for item in sitems %}
+                  {% include menu_single.html %}
                 {% endfor %}
-                
               {% endif %}
-            {% endfor %}
           </ul>
         </div>
       </li>
diff --git a/_includes/print_number.liquid b/_includes/print_number.liquid
deleted file mode 100644
index e72d51a..0000000
--- a/_includes/print_number.liquid
+++ /dev/null
@@ -1,10 +0,0 @@
-{% if value == null %}
-  {% assign value = site.defaults[0].values["menu_order"] %}
-{% endif %}
-
-{% if value < 10 %}0{% endif %}
-{% if value < 100 %}0{% endif %}
-{% if value < 1000 %}0{% endif %}
-{% if value < 10000 %}0{% endif %}
-
-{{value}}
\ No newline at end of file
-- 
GitLab