Giter Site home page Giter Site logo

Comments (15)

wkrsz avatar wkrsz commented on August 16, 2024 1

This works for me:

{% assign sorted_pages = site.pages | sort:"name" %}
{% for node in sorted_pages %}

Then add numerical prefixes to file names to order them.

Optionally fix permalinks:

---
layout: default
title: News
permalink: "index.html"
---

http://stackoverflow.com/questions/13266369/how-to-change-the-default-order-pages-in-jekyll/16625558#16625558

from jekyll-bootstrap.

 avatar commented on August 16, 2024

The only way to create your own order is to manually create an array in the _config.yml...

Some time ago I did this for category names. It works locally but it's not an option when using Github pages. In Github it seems that _config.yml is updated by merging any new change with the old values. When using {{ site.array }} the order is not guaranteed to be the same as in _config.yml

from jekyll-bootstrap.

plusjade avatar plusjade commented on August 16, 2024

@abyme that is a very good point and also explains why that happend to me a couple times =).

This makes it even harder to get proper ordering in Jekyll =/

from jekyll-bootstrap.

 avatar commented on August 16, 2024

It's not possible without plugins as far as I know. I currently list categories manually in a included template.

There is a way (at the end of that post) to do it, but it's possibly the worst hack ever.

from jekyll-bootstrap.

FlorianWolters avatar FlorianWolters commented on August 16, 2024

Concerning Github Pages: It is definitely the timestamp of the static .html files that are created by Jekyll which determines the ordering.

I wanted to order my website navigation but still use the following Jekyll-Bootstrap snippet (so that the default.html file of my theme remains generic):

{% assign pages_list = site.pages %}
{% assign group = 'navigation' %}
{% include JB/pages_list %}

I tried the following to achieve an ordering:

  1. Renamed all files which should be included in the navigation, e.g. 00-home.md, 01-about.md, etc.
  2. Tested the navigation output on my local computer with jekyll --server. => The navigation has the correct order.
  3. Pushed it to GitHub and tested the navigation output. => The navigation has a random order.

So, is there any possibility to get a custom ordering of the navigation and pages? It is definitely a huge drawback.

The only solution I see is to remove the Jekyll-Bootstrap code above and hardcode the navigation within the default.html file of my theme. But that isn't a good solution too, since themes should be as generic (and therefore usable for others) as possible.

from jekyll-bootstrap.

plusjade avatar plusjade commented on August 16, 2024

@FlorianWolters yep I agree, it is very annoying not being able to preserve order.

You may or may not really like this answer but after spending much time working on Jekyll Bootstrap, the next step in its evolution is ...

re-design how a static blogging generator can work. http://ruhoh.com is my project, it naturally supports ordered lists. The neat thing about ruhoh is all posts and pages have ids. Throughout the system you can reference the post/page by id, for example create an array of page ids, then the templater is smart enough to expand the id to the relevant post/page object.

It's outlined here: http://ruhoh.com/usage#to_pages

from jekyll-bootstrap.

FlorianWolters avatar FlorianWolters commented on August 16, 2024

@plusjade I appreciate your fast answer and your work on both static blogging generators.

I definitely like your answer and I will give Ruhoh a try.

Can you tell me something about the future of Jekyll-Bootstrap? Will you continue both projects or will Ruhoh supersede Jekyll-Bootstrap and the latter will be discontinued?

Nonetheless, you should clarify the future of Jekyll-Bootstrap on http://jekyllbootstrap.com.

from jekyll-bootstrap.

plusjade avatar plusjade commented on August 16, 2024

I will be committed to maintaining JB but work will be relegated to weekends mostly.

I created JB from my initial frustrations working with Jekyll. Most people praise Jekyll's ease of use but for me it took a lot of effort to grok how and why Jekyll was doing what it was doing. The biggest pain point for me as a programmer is shoehorning my mind into Liquid. I get why liquid is useful, but to a programmer on his own machine, it's blasphemy.

Jekyll is great because it popularized and solidified static blogging as a viable alternative. This is of course because Jekyll is made by GitHub and natively supported by GitHub.

Moving forward, I reflected on why I made JB in the first place. It was to help myself blog more. I've had many Wordpress sites, a posterous site, a sinatra site, and they all achieve the same thing - nothing. I never write in them. I realized the workflow was not motivating to me.

If my goal is to help people blog more, then prioritizing Jekyll-Bootstrap development has on fatal flaw -

no matter how feature-rich, intuitive and awesome JB gets, it will only ever be useful to ruby programers.

What to do?

There are countless other static blog generators out there, so I have to ask myself is making another one a good idea?

http://ruhoh.com is the only one I know of built to be language-agnostic. The api is heavily influenced by Jekyll and I'd argue using Mustache for templating is 54.67 trillion times better and easier than using Liquid. Mustache is of course supported in many languages

So to answer your question officially - I think the best use of my time, relative to my goal of empowering all developers to share their knowledge through blogging, is to commit to building a language-agnostic Universal Blogging API.

Lastly, I definitely agree about making my intentions clear on jekyllbootstrap.com. I'm just finishing up my hosting service for ruhoh, so as soon as I get the ruhoh.com site a bit more officialized, I'll update JB with a well-intentioned outline of the future of both products.

@FlorianWolters I appreciate the relevant questions and could use some feedback on what you think from a user perspective? Are you interested in trying out ruhoh's hosted service? username.ruhoh.com, just like GitHub - preview here

from jekyll-bootstrap.

balta2ar avatar balta2ar commented on August 16, 2024

I thought maybe one can add another tag to the header of .md file. Similar to group, but name it order and set to 1, 2, 3 etc according to the order you want your navigation to appear. Then in _includes/page_list you need to sort pages_list variable by that order. The only problem is that I don't know how to specity the field to use for comparison.

EDIT: found solution here: http://stackoverflow.com/questions/9053066/sorted-navigation-menu-with-jekyll-and-liquid

from jekyll-bootstrap.

arechsteiner avatar arechsteiner commented on August 16, 2024

This worked for my purposes: http://stackoverflow.com/a/9126294/1199685

from jekyll-bootstrap.

solkar avatar solkar commented on August 16, 2024

I wanted to use the custom array solution, and I struggled to find out the fields needs. Finally I came out with this,

in _config.yml, add:

custom_navigation_bar:
 - {title: foo_title1, group: navigation, url:bar_url1}
 - {title: foo_title2, group: navigation, url:bar_url2}

user your custom array inside default.html:

    <div class="navbar">
      <div class="navbar-inner">
        <div class="container-narrow">
          <a class="brand" href="{{ HOME_PATH }}">{{ site.title }}</a>
          <ul class="nav">
            {% assign pages_list = site.custom_navigation_bar %}
            {% assign group = 'navigation' %}
            {% include JB/pages_list %}
          </ul>
        </div>
     </div>
   </div>

from jekyll-bootstrap.

snowdream avatar snowdream commented on August 16, 2024

http://james.richardson.name/2013/04/sorting-lists-alphabetically-in-jekyll/index

from jekyll-bootstrap.

marshallshen avatar marshallshen commented on August 16, 2024

@snowdream 👍
Great idea, mind to submit a PR for a JB pluging?

from jekyll-bootstrap.

groundh0g avatar groundh0g commented on August 16, 2024

I think something like this should work. I tested it locally and all seems well.

JB/sort_collection

{% capture jbcache %}{% comment %}

  Sort the given array or map.

  Parameters:
    collection: the array or map to sort [REQUIRED]
    sort_by: the property to sort by [OPTIONAL]
    sort_descending: reverse the collection [OPTIONAL]

  Returns:
    sort_result: the sorted collection

  Examples:
    <h3>Pages</h3>
    <ol>
      {% include JB/sort_collection collection=site.pages sort_by="title" %}
      {% assign pages_list = sort_result %}
      {% include JB/pages_list %}
    </ol>

    <h3>Pages [Reversed]</h3>
    <ol>
      {% include JB/sort_collection collection=site.pages sort_by="title" sort_descending=true %}
      {% assign pages_list = sort_result %}
      {% include JB/pages_list %}
    </ol>

    <h3>Array</h3>
    <ol>
      {% assign test_array = "one,two,three,four" | split: "," %}
      {% include JB/sort_collection collection=test_array %}
      {% for test in sort_result %}
        <li>{{test}}</li>
      {% endfor %}
    </ol>

    <h3>Array [Reversed]</h3>
    <ol>
      {% assign test_array = "one,two,three,four" | split: "," %}
      {% include JB/sort_collection collection=test_array sort_descending=true %}
      {% for test in sort_result %}
        <li>{{test}}</li>
      {% endfor %}
    </ol>

{% endcomment %}

{% assign is_array = true %}
{% assign sort_result = "," | split: "," %}
{% assign collection = include.collection %}
{% if include.sort_by %}
  {% assign sort_by = include.sort_by %}
{% else %}
  {% assign sort_by = "title" %}
{% endif %}

{% if collection and collection.size > 0 %}
  {% for x in collection.first %}
    {% if x[1].size > 0 %}
      {% assign is_array = false %}
    {% endif %}
    {% break %}
  {% endfor %}

  {% if is_array == false %}
    {% assign sort_result = collection | sort: sort_by %}
  {% else %}
    {% assign sort_result = collection | sort %}
  {% endif %}

  {% if include.sort_descending %}
    {% assign reversed = "," | split: "," %}
    {% for index in (1..sort_result.size) %}
      {% assign i = sort_result.size | minus: index %}
      {% assign reversed = reversed | push: sort_result[i] %}
    {% endfor %}
    {% assign sort_result = reversed %}
    {% assign reversed = nil %}
  {% endif %}

{% endif %}{% endcapture %}{% assign jbcache = nil %}

I plan to create a PR for this tonight. Offering up for peer review.

EDIT: Updated code to support reversed sorts. Probably not going to issue PR tonight. But soon. So comment if you see something funky.

from jekyll-bootstrap.

groundh0g avatar groundh0g commented on August 16, 2024

Merged. Low risk. Stand-alone helper file.

from jekyll-bootstrap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.