Merge pull request #838 from mattr-/dedupe-entry-generation
Remove code duplication during site generation
This commit is contained in:
commit
df9964c3b5
|
@ -187,9 +187,7 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def read_posts(dir)
|
def read_posts(dir)
|
||||||
base = File.join(self.source, dir, '_posts')
|
entries = get_entries(dir, '_posts')
|
||||||
return unless File.exists?(base)
|
|
||||||
entries = Dir.chdir(base) { filter_entries(Dir['**/*']) }
|
|
||||||
|
|
||||||
# first pass processes, but does not yet render post content
|
# first pass processes, but does not yet render post content
|
||||||
entries.each do |f|
|
entries.each do |f|
|
||||||
|
@ -197,9 +195,7 @@ module Jekyll
|
||||||
post = Post.new(self, self.source, dir, f)
|
post = Post.new(self, self.source, dir, f)
|
||||||
|
|
||||||
if post.published && (self.future || post.date <= self.time)
|
if post.published && (self.future || post.date <= self.time)
|
||||||
self.posts << post
|
aggregate_post_info(post)
|
||||||
post.categories.each { |c| self.categories[c] << post }
|
|
||||||
post.tags.each { |c| self.tags[c] << post }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -212,18 +208,14 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def read_drafts(dir)
|
def read_drafts(dir)
|
||||||
base = File.join(self.source, dir, '_drafts')
|
entries = get_entries(dir, '_drafts')
|
||||||
return unless File.exists?(base)
|
|
||||||
entries = Dir.chdir(base) { filter_entries(Dir['**/*']) }
|
|
||||||
|
|
||||||
# first pass processes, but does not yet render draft content
|
# first pass processes, but does not yet render draft content
|
||||||
entries.each do |f|
|
entries.each do |f|
|
||||||
if Draft.valid?(f)
|
if Draft.valid?(f)
|
||||||
draft = Draft.new(self, self.source, dir, f)
|
draft = Draft.new(self, self.source, dir, f)
|
||||||
|
|
||||||
self.posts << draft
|
aggregate_post_info(draft)
|
||||||
draft.categories.each { |c| self.categories[c] << draft }
|
|
||||||
draft.tags.each { |c| self.tags[c] << draft }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -395,5 +387,28 @@ module Jekyll
|
||||||
raise "Converter implementation not found for #{klass}"
|
raise "Converter implementation not found for #{klass}"
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue