Refactor post and draft object creation
De-duplicate object creation between posts and drafts. Inject the name dependency through a parameter
This commit is contained in:
parent
e14fe116db
commit
e69d77b4df
|
@ -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
|
posts.each do |post|
|
||||||
entries.each do |f|
|
if post.published && (self.future || post.date <= self.time)
|
||||||
if Post.valid?(f)
|
aggregate_post_info(post)
|
||||||
post = Post.new(self, self.source, dir, f)
|
|
||||||
|
|
||||||
if post.published && (self.future || post.date <= self.time)
|
|
||||||
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,15 +185,16 @@ 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
|
drafts.each do |draft|
|
||||||
entries.each do |f|
|
aggregate_post_info(draft)
|
||||||
if Draft.valid?(f)
|
end
|
||||||
draft = Draft.new(self, self.source, dir, f)
|
end
|
||||||
|
|
||||||
aggregate_post_info(draft)
|
def read_things(dir, magic_dir, klass)
|
||||||
end
|
get_entries(dir, magic_dir).each_with_object([]) do |entry, things|
|
||||||
|
things << klass.new(self, self.source, dir, entry) if klass.valid?(entry)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue