From 2dd98816d48e2ebdf16e4d8ddf4fe76e787165ef Mon Sep 17 00:00:00 2001 From: Matt Rogers Date: Tue, 5 Mar 2013 19:06:20 -0600 Subject: [PATCH 1/2] Remove duplication when generating list of entries to process Posts and Drafts share the same logic to get the list of files to process into objects when generating the site. Factor this logic into its own method and use it when reading posts and reading drafts. --- lib/jekyll/site.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 18488431..f16b4387 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| @@ -212,9 +210,7 @@ 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| @@ -395,5 +391,17 @@ 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 end end From 6399ec9b2b07b4f8dbaf3dc72cac200a0185b2a8 Mon Sep 17 00:00:00 2001 From: Matt Rogers Date: Tue, 5 Mar 2013 19:11:07 -0600 Subject: [PATCH 2/2] Remove duplication when aggregating post information --- lib/jekyll/site.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index f16b4387..94c4b1a0 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -195,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 @@ -217,9 +215,7 @@ module Jekyll 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 @@ -403,5 +399,16 @@ module Jekyll 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