{% set configured = site.extra.get("sidebar", {}).get("sections", []) %} {% set found = namespace(names=[]) %} {% for item in pages %} {% set name = item.meta.get("section") %} {% if name and name not in found.names %} {% set found.names = found.names + [name] %} {% endif %} {% endfor %} {% set ordered = namespace(names=[]) %} {% for name in configured %} {% if name in found.names %}{% set ordered.names = ordered.names + [name] %}{% endif %} {% endfor %} {% for name in found.names | sort %} {% if name not in ordered.names %}{% set ordered.names = ordered.names + [name] %}{% endif %} {% endfor %}