Merge pull request #1779 from mojombo/no-duplication
Refactor post and draft object creation
This commit is contained in:
commit
362d28f11d
|
@ -169,19 +169,14 @@ module Jekyll
|
|||
#
|
||||
# Returns nothing.
|
||||
def read_posts(dir)
|
||||
entries = get_entries(dir, '_posts')
|
||||
|
||||
# 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 = read_things(dir, '_posts', Post)
|
||||
|
||||
posts.each do |post|
|
||||
if post.published && (self.future || post.date <= self.time)
|
||||
aggregate_post_info(post)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Read all the files in <source>/<dir>/_drafts and create a new Post
|
||||
# object with each one.
|
||||
|
@ -190,16 +185,17 @@ module Jekyll
|
|||
#
|
||||
# Returns nothing.
|
||||
def read_drafts(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)
|
||||
drafts = read_things(dir, '_drafts', Draft)
|
||||
|
||||
drafts.each do |draft|
|
||||
aggregate_post_info(draft)
|
||||
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
|
||||
|
||||
# Read and parse all yaml files under <source>/<dir>
|
||||
|
|
Loading…
Reference in New Issue