{%- capture _pass_stash -%}{{ _pass_stash }}{%- if _pass_active -%}1{%- else -%}0{%- endif -%}{%- endcapture -%} {%- assign _pass_active = false -%} {%- capture _menu_inside -%} {%- assign _pages = site.pages -%} {%- if include.sort -%} {%- assign _pages = _pages | sort: include.sort -%} {%- else -%} {%- assign _pages = _pages | sort: "url" -%} {%- endif -%} {%- if include.reverse -%} {%- assign _pages = _pages | reverse -%} {%- endif -%} {%- for node in _pages -%} {%- comment -%} The main difference between datamenu and automenu is that automenu (By virtue of it generating the menu automatically) doesn't know ahead of time what it's children are. Because of that, this entire first part is dedicated to looping through *all* pages and filtering out the ones that are not children of the current node. We also have to take special care with the "/" page as this could result in infinite recursion. {%- endcomment -%} {%- unless node.title -%} {%- continue -%} {%- endunless -%} {%- assign _url_start = node.url | truncate: include.url.size, "" -%} {%- unless include.url == _url_start -%} {%- continue -%} {%- endunless -%} {%- assign _url_rest = node.url | remove_first: _url_start -%} {%- assign _url_rest_size = _url_rest | split: "/" | size -%} {%- assign _lastchar = node.url | split: "" | last -%} {%- assign _nexturl = node.url -%} {%- if _url_rest_size == 0 -%} {%- unless include.url == "/" -%} {%- continue -%} {%- endunless -%} {%- elsif _lastchar == "/" -%} {%- unless _url_rest_size == 1 -%} {%- continue -%} {%- endunless -%} {%- elsif _url_rest_size == 2 -%} {%- assign _filename = _url_rest | split: "/" | last -%} {%- assign _checkindex = _filename | truncate: 6, "" -%} {%- unless _checkindex == "index." -%} {%- continue -%} {%- endunless -%} {%- assign _nexturl = node.url.size | minus: _filename.size -%} {%- assign _nexturl = node.url | truncate: _nexturl, "" -%} {%- else -%} {%- unless _url_rest_size == 1 and include.url == "/" -%} {%- continue -%} {%- endunless -%} {%- endif -%} {%- assign _retval = false -%} {%- assign _childmenu = "" -%} {%- unless node.url == "/" -%} {%- capture _childmenu -%}{%- include automenu.html url=_nexturl sort=include.sort reverse=include.reverse all=include.all -%}{%- endcapture -%} {%- endunless -%} {%- capture _classes -%} {%- if page.url == node.url -%} selected {{ " " }} {%- elsif _retval -%} active {{ " " }} {%- endif -%} {%- if _childmenu != "" -%} branch {{ " " }} {%- if _retval or page.url == node.url or include.all -%} open {%- else -%} closed {%- endif -%} {%- else -%} leaf {%- endif -%} {%- endcapture -%}
  • {{ node.title | escape }} {%- if _retval or page.url == node.url or include.all -%}{{ _childmenu }}{%- endif -%} {%- if _retval or page.url == node.url -%}{%- assign _pass_active = true -%}{%- endif -%}
  • {%- endfor -%} {%- endcapture -%} {%- unless _menu_inside == "" -%} {%- endunless -%} {%- assign _retval = _pass_active -%} {%- assign _tmp = _pass_stash | split: "" | last -%} {%- if _tmp == "1" -%} {%- assign _pass_active = true -%} {%- else -%} {%- assign _pass_active = false -%} {%- endif -%} {%- assign _tmp = _pass_stash.size | minus: 1 -%} {%- assign _pass_stash = _pass_stash | truncate: _tmp, "" -%}