Merge pull request #1779 from mojombo/no-duplication

Refactor post and draft object creation
This commit is contained in:
Matt Rogers 2013-12-06 20:58:24 -08:00
commit 362d28f11d
1 changed files with 13 additions and 17 deletions

View File

@ -169,19 +169,14 @@ module Jekyll
# #
# Returns nothing. # Returns nothing.
def read_posts(dir) def read_posts(dir)
entries = get_entries(dir, '_posts') posts = read_things(dir, '_posts', Post)
# first pass processes, but does not yet render post content
entries.each do |f|
if Post.valid?(f)
post = Post.new(self, self.source, dir, f)
posts.each do |post|
if post.published && (self.future || post.date <= self.time) if post.published && (self.future || post.date <= self.time)
aggregate_post_info(post) aggregate_post_info(post)
end end
end end
end end
end
# Read all the files in <source>/<dir>/_drafts and create a new Post # Read all the files in <source>/<dir>/_drafts and create a new Post
# object with each one. # object with each one.
@ -190,16 +185,17 @@ module Jekyll
# #
# Returns nothing. # Returns nothing.
def read_drafts(dir) def read_drafts(dir)
entries = get_entries(dir, '_drafts') drafts = read_things(dir, '_drafts', Draft)
# 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)
drafts.each do |draft|
aggregate_post_info(draft) aggregate_post_info(draft)
end end
end end
def read_things(dir, magic_dir, klass)
things = get_entries(dir, magic_dir).map do |entry|
klass.new(self, self.source, dir, entry) if klass.valid?(entry)
end
end end
# Read and parse all yaml files under <source>/<dir> # Read and parse all yaml files under <source>/<dir>