lib/nanoc/helpers/blogging.rb in nanoc-3.6.11 vs lib/nanoc/helpers/blogging.rb in nanoc-3.7.0
- old
+ new
@@ -26,21 +26,32 @@
# Returns an unsorted list of articles, i.e. items where the `kind`
# attribute is set to `"article"`.
#
# @return [Array] An array containing all articles
def articles
- @items.select { |item| item[:kind] == 'article' }
+ blk = lambda { @items.select { |item| item[:kind] == 'article' } }
+ if @items.frozen?
+ @article_items ||= blk.call
+ else
+ blk.call
+ end
end
# Returns a sorted list of articles, i.e. items where the `kind`
# attribute is set to `"article"`. Articles are sorted by descending
# creation date, so newer articles appear before older articles.
#
# @return [Array] A sorted array containing all articles
def sorted_articles
- articles.sort_by do |a|
- attribute_to_time(a[:created_at])
- end.reverse
+ blk = lambda do
+ articles.sort_by { |a| attribute_to_time(a[:created_at]) }.reverse
+ end
+
+ if @items.frozen?
+ @sorted_article_items ||= blk.call
+ else
+ blk.call
+ end
end
class AtomFeedBuilder
include Nanoc::Helpers::Blogging