{% if nav|length > 1 %}
{% if config.theme.topbar_sections %}
{% set current = nav|active_section|attr('children') %}
{% else %}
{% set current = nav %}
{% endif %}
{% if not current %}
{# when there is not active section, keep only the top level pages #}
{% set current = nav|selectattr("is_page") %}
{% endif %}
{% set pages = current|selectattr("is_page")|sort(attribute="meta.order") %}
{% set sections = current|rejectattr("is_page")|list %}
{% if pages|length > 0 %}
{% for page in pages %}
{% with sidebar_item = page %}
{% include "components/sidebar_item.html" %}
{% endwith %}
{% endfor %}
{% endif %}
{% for section in sections %}
{% if section.children %}
{{ section.title }}
{% for sidebar_item in section.children|selectattr("is_page")|sort(attribute="meta.order") %}
{% include "components/sidebar_item.html" %}
{% endfor %}