-
-
Save lrenhrda/9949419 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Jekyll | |
| class CategoryAwareNextPrevGenerator < 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 | |
| if position && position > 0 | |
| category_prev = posts[position - 1] | |
| else | |
| category_prev = nil | |
| end | |
| post.data["#{category_name}_next"] = category_next unless category_next.nil? | |
| post.data["#{category_name}_prev"] = category_prev unless category_prev.nil? | |
| end | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment