{% assign lastSixCharsOfPageUrl = page.url | slice: -6, 6 %}

{% if lastSixCharsOfPageUrl == '/index' %}
  {% assign lengthOfPageUrlWithoutIndex = page.url | size | minus: 6 %}
  {% assign pageUrlWithoutIndex = page.url | slice: 0, lengthOfPageUrlWithoutIndex %}
{% else %}
  {% assign pageUrlWithoutIndex = page.url %}
{% endif %}

{%
  assign matchingPages = site.pages
    | where_exp: "page", "
      page.id contains include.path
    "
    | sort: "order"
    | sort: "parent.order"
%}

<ul class="TreeMenu-