Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the default order pages in Jekyll?

My blog is built with Jekyll on Github. In the navigation bar, the default order is Pages, Messages, About, Archives. I want to change the list to Pages, Archives, About, Messages. What should I do?

I think it is related to the code below

{% assign pages_list = site.pages %} 

I think site.pages is what I should change, but I don't know how.

like image 612
Ever Avatar asked Nov 07 '12 09:11

Ever


People also ask

How do I change my homepage on Jekyll?

You can use gem 'jekyll-redirect-from' in jekyll to set different homepage than index. html and also customize output URL of any xxxx. html. As a result, www.website.com/about will redirect to www.website.com and content of about.


1 Answers

You can create custom order of your menu items like this:

  1. In your pages front matter add the order field (you can name it as you prefer)
    --- layout: default published: true title: Page title order: 1 --- 
  2. When getting pages, apply the 'sort' filter
    {% assign sorted_pages = site.pages | sort:"order" %} {% for node in sorted_pages %}   <li><a href="{{node.url}}">{{node.title}}</a></li> {% endfor %} 

You'll end up with an ordered (ASC) list of pages, based on the 'order' field value you add to each page.

like image 68
Victor Stegaru Avatar answered Sep 21 '22 16:09

Victor Stegaru