Skip to content

A very simple Jekyll plugin that allows you to sort lists under the site var and store the results back under the site var.

Notifications You must be signed in to change notification settings

kylepaulsen/Jekyll-Sort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

JekyllSort

Copyright © 2012 Kyle Paulsen. All Rights Reserved.
Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)

What is it?

For those of you who have some list and want to sort it in jekyll, this plugin will sort lists of primitives and lists of hashes based on a direction and what to sort on (if needed). It stores the sorted answer in the global site var for usage. If you have lists of hashes of hashes and you want to sort on something deeper than the first level, then you can edit this code.

Usage:

  • Put jekyll_sort.rb in your _plugins directory.
  • Edit your _config.yml to have a jekyll_sort property and make it look something like this:
jekyll_sort:
  - src: numbers
    direction: up
    dest: numbers_sorted
  - src: posts
    by: some_property
    direction: down
    dest: posts_sorted_by_something
  - src: all_content
    by: sort
    direction: down
    dest: all_promoted_by_sort
    include_tags: 
    - promoted
    - news
  • The dash src: attribute specifies what object to sort on. It needs to be in the site var.
  • The by: attribute is for sorting lists of hashes on some hash property. It is only required if you have a list of hashes. Also, you can use an attribute called “sort” which will sort your content arbitrarily by the numeric weight you assign
  • The direction: attribute specifies what direction you want your list to be sorted (up | down). It is only required if you want to sort down. (It is “up” by default)
  • The dest: attribute specifies what site object should hold the sorted list.
  • Posts can be sorted by any property you define in your yaml front matter as well as the properties ‘url’, ‘content’ or ‘date’
  • include_tags: reduce your new collection based on content that includes certain tags
  • Generate your pages like normal! Your sorted lists will be attached to your global site var under their dest attributes for every page.

Update History: (most recent first)

  • 21-Oct-2012 kyle paulsen — allow posts to actually be sorted.
  • 20-Jun-2012 kyle paulsen — First public release.

About

A very simple Jekyll plugin that allows you to sort lists under the site var and store the results back under the site var.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages