@@ -112,42 +112,24 @@ def write
112
112
end
113
113
end
114
114
115
- # Construct a Hash of Posts indexed by the specified Post attribute.
116
- #
117
- # post_attr - The String name of the Post attribute.
118
- #
119
- # Examples
120
- #
121
- # post_attr_hash('categories')
122
- # # => { 'tech' => [<Post A>, <Post B>],
123
- # # 'ruby' => [<Post B>] }
124
- #
125
- # Returns the Hash: { attr => posts } where
126
- # attr - One of the values for the requested attribute.
127
- # posts - The Array of Posts with the given attr value.
128
- #
129
- # Taken from jekyll/jekyll (Copyright (c) 2014 Tom Preston-Werner under the MIT).
130
- def post_attr_hash ( post_attr )
131
- # Build a hash map based on the specified post attribute ( post attr =>
132
- # array of posts ) then sort each array in reverse order.
133
- hash = Hash . new { |h , key | h [ key ] = [ ] }
134
- @posts . each { |p | p . send ( post_attr . to_sym ) . each { |t | hash [ t ] << p } }
135
- hash . values . each { |posts | posts . sort! . reverse! }
136
- hash
137
- end
138
-
139
115
def tags
140
- post_attr_hash ( 'tags' )
116
+ @site . post_attr_hash ( 'tags' )
141
117
end
142
118
143
119
def categories
144
- post_attr_hash ( 'categories' )
120
+ @site . post_attr_hash ( 'categories' )
145
121
end
146
122
147
123
# Custom `post_attr_hash` method for years
148
124
def years
149
125
hash = Hash . new { |h , key | h [ key ] = [ ] }
150
- @posts . each { |p | hash [ p . date . strftime ( "%Y" ) ] << p }
126
+
127
+ # In Jekyll 3, Collection#each should be called on the #docs array directly.
128
+ if Jekyll ::VERSION >= '3.0.0'
129
+ @posts . docs . each { |p | hash [ p . date . strftime ( "%Y" ) ] << p }
130
+ else
131
+ @posts . each { |p | hash [ p . date . strftime ( "%Y" ) ] << p }
132
+ end
151
133
hash . values . each { |posts | posts . sort! . reverse! }
152
134
hash
153
135
end
0 commit comments