diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index b0bbd481..57f6545e 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -92,6 +92,7 @@ module Jekyll self.pages = [] self.static_files = [] self.data = {} + @post_attr_hash = {} @site_data = nil @collections = nil @docs_to_write = nil @@ -232,12 +233,14 @@ module Jekyll def post_attr_hash(post_attr) # Build a hash map based on the specified post attribute ( post attr => # array of posts ) then sort each array in reverse order. - hash = Hash.new { |h, key| h[key] = [] } - posts.docs.each do |p| - p.data[post_attr]&.each { |t| hash[t] << p } + @post_attr_hash[post_attr] ||= begin + hash = Hash.new { |h, key| h[key] = [] } + posts.docs.each do |p| + p.data[post_attr]&.each { |t| hash[t] << p } + end + hash.each_value { |posts| posts.sort!.reverse! } + hash end - hash.each_value { |posts| posts.sort!.reverse! } - hash end def tags