diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 18488431..94c4b1a0 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -187,9 +187,7 @@ module Jekyll # # Returns nothing. def read_posts(dir) - base = File.join(self.source, dir, '_posts') - return unless File.exists?(base) - entries = Dir.chdir(base) { filter_entries(Dir['**/*']) } + entries = get_entries(dir, '_posts') # first pass processes, but does not yet render post content entries.each do |f| @@ -197,9 +195,7 @@ module Jekyll post = Post.new(self, self.source, dir, f) if post.published && (self.future || post.date <= self.time) - self.posts << post - post.categories.each { |c| self.categories[c] << post } - post.tags.each { |c| self.tags[c] << post } + aggregate_post_info(post) end end end @@ -212,18 +208,14 @@ module Jekyll # # Returns nothing. def read_drafts(dir) - base = File.join(self.source, dir, '_drafts') - return unless File.exists?(base) - entries = Dir.chdir(base) { filter_entries(Dir['**/*']) } + entries = get_entries(dir, '_drafts') # first pass processes, but does not yet render draft content entries.each do |f| if Draft.valid?(f) draft = Draft.new(self, self.source, dir, f) - self.posts << draft - draft.categories.each { |c| self.categories[c] << draft } - draft.tags.each { |c| self.tags[c] << draft } + aggregate_post_info(draft) end end end @@ -395,5 +387,28 @@ module Jekyll raise "Converter implementation not found for #{klass}" end end + + # Read the entries from a particular directory for processing + # + # dir - The String relative path of the directory to read + # subfolder - The String directory to read + # + # Returns the list of entries to process + def get_entries(dir, subfolder) + base = File.join(self.source, dir, subfolder) + return [] unless File.exists?(base) + entries = Dir.chdir(base) { filter_entries(Dir['**/*']) } + end + + # Aggregate post information + # + # post - The Post object to aggregate information for + # + # Returns nothing + def aggregate_post_info(post) + self.posts << post + post.categories.each { |c| self.categories[c] << post } + post.tags.each { |c| self.tags[c] << post } + end end end