Sorted navigation menu with Jekyll and Liquid

后端 未结 10 2213
清酒与你
清酒与你 2020-12-07 11:57

I\'m constructing a static site (no blog) with Jekyll/Liquid. I want it to have an auto-generated navigation menu that lists all existing pages and highlight the current pag

10条回答
  •  醉酒成梦
    2020-12-07 12:40

    If you're trying to sort by weight and by tag and limit the number to 10, here's code to do it:

    {% assign counter = '0' %}
    {% assign pages = site.pages | sort: "weight"  %}
    {% for page in pages %}
    {% for tag in page.tags %}
    {% if tag == "Getting Started" and counter < '9' %}
    {% capture counter %}{{ counter | plus:'1' }}{% endcapture %}
    
  • {{page.title}}
  • {% endif %} {% endfor %} {% endfor %}

提交回复
热议问题