如何使用Jekyll和Liquid提升列表顺序?

Kod*_*ejn 4 liquid jekyll

我从Liquid&Jekyll开始,任何人都可以帮助我提升列表顺序(按{{category}}名称)吗?

<div class="col-xs-6 col-sm-3 patickaborder">
                <h5>Rubriky</h5>
                    <ul>
                        {% for category in site.categories order:ascending %}
                            <li><a href="{{ site.url }}{{ category | first }}/index.html">{{ category | first }}</a></li>
                        {% endfor %}
                    </ul>
            </div>
Run Code Online (Sandbox Code Playgroud)

小智 11

刚刚发现了这个.您可以对列表进行排序并将其分配给变量,然后在标记中使用它,如下所示:

{% assign sortedcats = site.categories | sort %}

<div class="col-xs-6 col-sm-3 patickaborder">
    <h5>Rubriky</h5>
        <ul>
            {% for category in sortedcats %}
                <li><a href="{{ site.url }}{{ category | first }}/index.html">{{ category | first }}</a></li>
            {% endfor %}
        </ul>
</div>
Run Code Online (Sandbox Code Playgroud)