      assign numChildren = site.pages
        | where_exp: "page", "
          page.id contains pathWithoutIndex
        "
        | size
    %}

    {% assign depth = matchingPage.id | split: '/' | size %}

    {%
      assign depthWithoutReadme = pathWithoutIndex
        | split: '/'
        | size
    %}

    {%
      assign targetDepth = include.path
        | split: '/'
        | size
        | plus: 1
    %}

    {% if depth == targetDepth or depthWithoutReadme == targetDepth and numChildren == 1 %}
 