Skip to content
Browse files

Ensure posts hashes are built properly before all HAML/HTML file gene…

…ration.

This is needed to handle multiple blogs (i.e., multiple _posts
directories) properly so that the global set of "posts" across the entire
site are built properly before any code in HAML files or Liquid templates
attempt to access variables.  Unexpected and surprising results occur when
there are multiple _posts directories throughout the tree otherwise.

Also, sorting categories seemed wrong to me, since I don't want the
directory order to change from what I set up for the blog URL.
  • Loading branch information...
1 parent 9e923f8 commit 0ab97f797c3593e8d3def7c1ee3808db212e75c6 @bkuhn committed Aug 16, 2009
Showing with 26 additions and 4 deletions.
  1. +1 −1 lib/jekyll/post.rb
  2. +25 −3 lib/jekyll/site.rb
View
2 lib/jekyll/post.rb
@@ -137,7 +137,7 @@ def generated_path
"month" => date.strftime("%m"),
"day" => date.strftime("%d"),
"title" => slug,
- "categories" => categories.sort.join('/')
+ "categories" => categories.join('/')
}.inject(template) { |result, token|
result.gsub(/:#{token.first}/, token.last)
}.gsub("//", "/")
View
28 lib/jekyll/site.rb
@@ -123,6 +123,8 @@ def textile(content)
def process
self.reset
self.read_layouts
+ self.recurse_handle_posts
+ self.coordinate_posts
self.transform_pages
self.transform_sass if self.sass
self.write_posts
@@ -154,6 +156,7 @@ def read_posts(dir)
# first pass processes, but does not yet render post content
entries.each do |f|
+ print "Creating from dir: ", dir, " the post ", f, "\n"
if Post.valid?(f)
post = Post.new(self, self.source, dir, f)
@@ -164,7 +167,9 @@ def read_posts(dir)
end
end
end
+ end
+ def coordinate_posts()
self.posts.sort!
# second pass renders each post now that full site payload is available
@@ -188,6 +193,24 @@ def write_posts
end
end
+ def recurse_handle_posts(dir = '')
+ base = File.join(self.source, dir)
+ entries = filter_entries(Dir.entries(base))
+ directories = entries.select { |e| File.directory?(File.join(base, e)) }
+
+ # we need to make sure to process _posts *first* otherwise they
+ # might not be available yet to other templates as {{ site.posts }}
+ if directories.include?('_posts')
+ FileUtils.mkdir_p(File.join(self.dest, dir))
+ read_posts(dir)
+ end
+ directories.each do |newDir|
+ if File.directory?(File.join(base, newDir))
+ next if self.dest.sub(/\/$/, '') == File.join(base, newDir)
+ recurse_handle_posts(File.join(dir, newDir))
+ end
+ end
+ end
# Copy all regular files from <source> to <dest>/ ignoring
# any files/directories that are hidden or backup files (start
# with "." or "#" or end with "~") or contain site content (start with "_")
@@ -203,11 +226,10 @@ def transform_pages(dir = '')
directories = entries.select { |e| File.directory?(File.join(base, e)) }
files = entries.reject { |e| File.directory?(File.join(base, e)) }
- # we need to make sure to process _posts *first* otherwise they
- # might not be available yet to other templates as {{ site.posts }}
+ # we need to remove _posts here, they were previously processed by
+ # recurse_handle_posts
if directories.include?('_posts')
directories.delete('_posts')
- read_posts(dir)
end
[directories, files].each do |entries|
entries.each do |f|

0 comments on commit 0ab97f7

Please sign in to comment.
Something went wrong with that request. Please try again.