jekyll-category-aware-prev-next 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ module Jekyll
2
+ class CategoryAwarePrevNextGenerator < Generator
3
+
4
+ safe true
5
+ priority :high
6
+
7
+ def generate(site)
8
+ site.categories.each_pair do |category_name, posts|
9
+ posts.sort! { |a, b| a <=> b }
10
+
11
+ posts.each do |post|
12
+ position = posts.index post
13
+
14
+ if position && position < posts.length - 1
15
+ category_next = posts[position + 1]
16
+ else
17
+ category_next = nil
18
+ end
19
+
20
+ if position && position > 0
21
+ category_previous = posts[position - 1]
22
+ else
23
+ category_previous = nil
24
+ end
25
+
26
+ post.data["cat_next"] = category_next unless category_next.nil?
27
+ post.data["cat_previous"] = category_previous unless category_previous.nil?
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-category-aware-prev-next
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Beni Buess
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-21 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: jekyll-category-aware-prev-next adds category aware cat_next and cat_previous
15
+ to posts since jekyll's next and prev do not take the category into account
16
+ email: beni@benel.net
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/jekyll-category-aware-prev-next.rb
22
+ homepage: http://github.com/benib/jekyll-category-aware-prev-next
23
+ licenses: []
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 1.8.11
43
+ signing_key:
44
+ specification_version: 3
45
+ summary: jekyll-category-aware-prev-next adds cat_next and cat_previous to posts
46
+ test_files: []