Skip to content

Commit fdbaa07

Browse files
Paul Robert Lloydalfredxing
authored andcommitted
Test for support for @posts.docs
Signed-off-by: Alfred Xing <[email protected]>
1 parent 07bb058 commit fdbaa07

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/jekyll-archives.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,13 @@ def post_attr_hash(post_attr)
131131
# Build a hash map based on the specified post attribute ( post attr =>
132132
# array of posts ) then sort each array in reverse order.
133133
hash = Hash.new { |h, key| h[key] = [] }
134-
@posts.docs.each { |p| p.data[post_attr].each { |t| hash[t] << p } }
134+
135+
# In Jekyll 3, Collection#each should be called on the #docs array directly.
136+
if defined? @posts.docs
137+
@posts.docs.each { |p| p.data[post_attr].each { |t| hash[t] << p } }
138+
else
139+
@posts.each { |p| p.send(post_attr.to_sym).each { |t| hash[t] << p } }
140+
end
135141
hash.values.each { |posts| posts.sort!.reverse! }
136142
hash
137143
end
@@ -147,7 +153,13 @@ def categories
147153
# Custom `post_attr_hash` method for years
148154
def years
149155
hash = Hash.new { |h, key| h[key] = [] }
150-
@posts.docs.each { |p| hash[p.date.strftime("%Y")] << p }
156+
157+
# In Jekyll 3, Collection#each should be called on the #docs array directly.
158+
if defined? @posts.docs
159+
@posts.docs.each { |p| hash[p.date.strftime("%Y")] << p }
160+
else
161+
@posts.each { |p| hash[p.date.strftime("%Y")] << p }
162+
end
151163
hash.values.each { |posts| posts.sort!.reverse! }
152164
hash
153165
end

0 commit comments

Comments
 (0)