Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Next and previous navigation in categories #520

Closed
wants to merge 1 commit into from

1 participant

@sparanoid

Added next_in_categories and previous_in_categories.

@sparanoid sparanoid closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 31 additions and 9 deletions.
  1. +31 −9 lib/jekyll/post.rb
View
40 lib/jekyll/post.rb
@@ -219,15 +219,17 @@ def write(dest)
# Returns <Hash>
def to_liquid
self.data.deep_merge({
- "title" => self.data["title"] || self.slug.split('-').select {|w| w.capitalize! || w }.join(' '),
- "url" => self.url,
- "date" => self.date,
- "id" => self.id,
- "categories" => self.categories,
- "next" => self.next,
- "previous" => self.previous,
- "tags" => self.tags,
- "content" => self.content })
+ "title" => self.data["title"] || self.slug.split('-').select {|w| w.capitalize! || w }.join(' '),
+ "url" => self.url,
+ "date" => self.date,
+ "id" => self.id,
+ "categories" => self.categories,
+ "next" => self.next,
+ "next_in_categories" => self.next_in_categories,
+ "previous" => self.previous,
+ "previous_in_categories" => self.previous_in_categories,
+ "tags" => self.tags,
+ "content" => self.content })
end
def inspect
@@ -252,6 +254,26 @@ def previous
nil
end
end
+
+ def next_in_categories
+ set = self.categories.map { |cat| self.site.categories[cat] }.flatten.uniq.sort
+ pos = set.index(self)
+ if pos && pos < set.length-1
+ set[pos+1]
+ else
+ nil
+ end
+ end
+
+ def previous_in_categories
+ set = self.categories.map { |cat| self.site.categories[cat] }.flatten.uniq.sort
+ pos = set.index(self)
+ if pos && pos > 0
+ set[pos-1]
+ else
+ nil
+ end
+ end
end
end
Something went wrong with that request. Please try again.