7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/jekyll-category-aware-prev-next.rb', line 7
def generate(site)
site.categories.each_pair do |category_name, posts|
posts.sort! { |a, b| a <=> b }
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_previous = posts[position - 1]
else
category_previous = nil
end
post.data["cat_next"] = category_next unless category_next.nil?
post.data["cat_previous"] = category_previous unless category_previous.nil?
end
end
end
|