Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor post and draft object creation #1779

Merged
merged 2 commits into from Dec 7, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 13 additions & 17 deletions lib/jekyll/site.rb
Expand Up @@ -169,19 +169,14 @@ def read_directories(dir = '')
#
# Returns nothing.
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)

if post.published && (self.future || post.date <= self.time)
aggregate_post_info(post)
end
posts.each do |post|
if post.published && (self.future || post.date <= self.time)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be post.published?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does published? do the same thing as published (without the question mark)? (this is rhetorical, I'll answer this myself)

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.
Expand All @@ -190,15 +185,16 @@ def read_posts(dir)
#
# Returns nothing.
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)
end
end

aggregate_post_info(draft)
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

Expand Down