Permalink
Browse files

Added weighted pages plugin.

  • Loading branch information...
1 parent 3d51b5a commit 043a319f51ca83a0422c6e707717c77ba3dd9073 @underdude underdude committed Apr 17, 2012
Showing with 25 additions and 1 deletion.
  1. +8 −1 README.md
  2. +17 −0 weighted_pages.rb
View
@@ -10,15 +10,22 @@ Overview
Plugins included in this repository:
* **strip.rb** - Block tag for trimming away unwanted newlines and whitespace between them.
+* **weighted_pages.rb** - Generates a page listing with pages sorted by a weight attribute.
Usage
-----
-### Strip.rb
+### strip.rb
Using eg. forloops to generate navigation produces often a huge amount of ugly whitespace. Wrapping the section with `{% strip %}{% endstrip %}` replaces the blocks of whitespace with one newline resulting in pretty markup.
+### weighted_pages.rb
+
+Add `weight` attribute to the front matter of your pages (like `weight: 1`) and use `site.weighted_pages` instead of `site.pages` in your loops.
+
+Pages without the attribute are sorted to the end of the list (in the default order).
+
Author
------
View
@@ -0,0 +1,17 @@
+# Generates a copy of site.pages as site.weighted_pages
+# with pages sorted by weight attribute. Pages with no
+# weight specified are placed after the pages with specified weight.
+
+module Jekyll
+
+ class WeightedPagesGenerator < Generator
+ safe true
+
+ def generate(site)
+ site.config['weighted_pages'] = site.pages.sort_by { |a|
+ a.data['weight'] ? a.data['weight'] : site.pages.length }
+ end
+
+ end
+
+end

0 comments on commit 043a319

Please sign in to comment.