Sorted navigation menu with Jekyll and Liquid

后端 未结 10 2217
清酒与你
清酒与你 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:57

    Easy solution:

    Assign a sorted array of site.pages first then run a for loop on the array.

    Your code will look like:

    {% assign links = site.pages | sort: 'weight' %}
    {% for p in links %}
      
  • {{ p.title }}
  • {% endfor %}

    This works in my navbar _include which is simply:

    
    

提交回复
热议问题