improve sidebar sorting

Instead of sorting by title then sort_key, sort by sort_key first and
then by title within a single sort_key. Also ensure documents without
sort_key come after pages with.
This commit is contained in:
Felix Lange 2019-11-01 22:46:52 +01:00
parent 44ca35842d
commit e643c1fc0a

View file

@ -6,23 +6,26 @@ layout: default
<div class="container" style="padding-top: 24px;"> <div class="container" style="padding-top: 24px;">
<div class="row"> <div class="row">
<div class="col-md-3" id="toc" style="padding-top: 16px;"> <div class="col-md-3" id="toc" style="padding-top: 16px;">
{% for group in toplevels %} {% for collection in toplevels %}
{% assign frontdoc=group.docs| where_exp: "doc","doc.path == group.frontpage"|first %} {% assign frontdoc = collection.docs | where_exp: "doc","doc.path == collection.frontpage" | first %}
{% unless frontdoc %} {% unless frontdoc %}
{% assign frontdoc=group.docs[0] %} {% assign frontdoc = collection.docs[0] %}
{% endunless %} {% endunless %}
{% capture target %}{% include link.html url=frontdoc.url %}{% endcapture %} {% capture target %}{% include link.html url=frontdoc.url %}{% endcapture %}
<div class="list-group"> <div class="list-group">
<a class="list-group-item active" href="{{ target |strip }}">{{ group.caption }}</a> <a class="list-group-item active" href="{{ target |strip }}">{{ collection.caption }}</a>
{% if page.collection == group.label %} {% if page.collection == collection.label %}
{% assign subpages = group.docs | sort_natural:"title" | sort:"sort_key" %} {% assign docs_by_sort_key = collection.docs | group_by:"sort_key" | sort:"name", "last" %}
{% for doc in subpages %} {% for group in docs_by_sort_key %}
{% assign docs_sorted = group.items | sort:"title" %}
{% for doc in docs_sorted %}
{% assign classmodifier="" %} {% assign classmodifier="" %}
{% if doc.url == page.url %} {% if doc.url == page.url %}
{% assign classmodifier="disabled" %} {% assign classmodifier="disabled" %}
{% endif %} {% endif %}
{% capture target %}{% include link.html url=doc.url %}{% endcapture %} {% capture target %}{% include link.html url=doc.url %}{% endcapture %}
<a class="list-group-item {{classmodifier}}" href="{{ target |strip }}">{% include title.html doc=doc coll=group %}</a> <a class="list-group-item {{classmodifier}}" href="{{ target |strip }}">{% include title.html doc=doc coll=collection %}</a>
{% endfor %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</div> </div>