Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save salemine/1259d4eb36c6670afbf0 to your computer and use it in GitHub Desktop.

Select an option

Save salemine/1259d4eb36c6670afbf0 to your computer and use it in GitHub Desktop.

Revisions

  1. @stravid stravid created this gist Nov 15, 2012.
    25 changes: 25 additions & 0 deletions category_aware_next_generator.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    module Jekyll
    class CategoryAwareNextGenerator < Generator

    safe true
    priority :high

    def generate(site)
    site.categories.each_pair do |category_name, posts|
    posts.sort! { |a, b| b <=> a }

    posts.each do |post|
    position = posts.index post

    if position && position < posts.length - 1
    category_next = posts[position + 1]
    else
    category_next = nil
    end

    post.data["#{category_name}_next"] = category_next unless category_next.nil?
    end
    end
    end
    end
    end