Comments (15)
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"
---
from jekyll-bootstrap.
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.
@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.
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.
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:
- Renamed all files which should be included in the navigation, e.g.
00-home.md
,01-about.md
, etc. - Tested the navigation output on my local computer with
jekyll --server
. => The navigation has the correct order. - 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.
@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.
@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.
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.
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.
This worked for my purposes: http://stackoverflow.com/a/9126294/1199685
from jekyll-bootstrap.
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.
http://james.richardson.name/2013/04/sorting-lists-alphabetically-in-jekyll/index
from jekyll-bootstrap.
@snowdream 👍
Great idea, mind to submit a PR for a JB pluging?
from jekyll-bootstrap.
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.
Merged. Low risk. Stand-alone helper file.
from jekyll-bootstrap.
Related Issues (20)
- Jekyll-bootstrap Rewrite ... v1.0.0
- Theme breaks when viewing an added post (following "quick start" in manual) HOT 2
- Can't include theme in posts HOT 3
- ERROR `/assets/themes/bootstrap/css/bootstrap.min.css' not found HOT 8
- it show in my local server but doesn't work in github pages
- The built-in Disqus now requires visitors to load unsafe scripts on https in order to comment. HOT 4
- Integrate Font Awesome release 4.6
- Page layout is broken HOT 5
- Support Bootstrap 4
- syntax highlighting not working HOT 1
- cant switch themes
- not manageable
- the resource path is wrong HOT 4
- Themes not working HOT 2
- Nested list does not work HOT 1
- Sorry this page does not exist =( HOT 3
- http://jekyllbootstrap.com is 404 HOT 2
- themes.jekyllbootstrap.com does not load HOT 1
- _config.yml changes are not reflecting on generated website.
- ERROR `/assets/themes/bootstrap-3/bootstrap/css/bootstrap.min.css' not found. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jekyll-bootstrap.