Fix site payload available to files
This commit is contained in:
parent
4b2fa43642
commit
d9b183f998
|
@ -2,7 +2,7 @@ module Jekyll
|
|||
|
||||
class Site
|
||||
attr_accessor :source, :dest
|
||||
attr_accessor :layouts, :posts
|
||||
attr_accessor :layouts, :posts, :categories
|
||||
|
||||
# Initialize the site
|
||||
# +source+ is String path to the source directory containing
|
||||
|
@ -16,6 +16,7 @@ module Jekyll
|
|||
self.dest = dest
|
||||
self.layouts = {}
|
||||
self.posts = []
|
||||
self.categories = Hash.new { |hash, key| hash[key] = Array.new }
|
||||
end
|
||||
|
||||
# Do the actual work of processing the site and generating the
|
||||
|
@ -63,6 +64,7 @@ module Jekyll
|
|||
if Post.valid?(f)
|
||||
post = Post.new(self.source, dir, f)
|
||||
self.posts << post
|
||||
post.categories.each { |c| self.categories[c] << post }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -72,6 +74,7 @@ module Jekyll
|
|||
end
|
||||
|
||||
self.posts.sort!
|
||||
self.categories.values.map { |cats| cats.sort! { |a, b| b <=> a} }
|
||||
rescue Errno::ENOENT => e
|
||||
# ignore missing layout dir
|
||||
end
|
||||
|
@ -101,6 +104,8 @@ module Jekyll
|
|||
entries = entries.reject do |e|
|
||||
(e != '_posts') and ['.', '_'].include?(e[0..0]) unless ['.htaccess'].include?(e)
|
||||
end
|
||||
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 }}
|
||||
|
@ -108,7 +113,7 @@ module Jekyll
|
|||
entries.delete('_posts')
|
||||
read_posts(dir)
|
||||
end
|
||||
|
||||
[directories, files].each do |entries|
|
||||
entries.each do |f|
|
||||
if File.directory?(File.join(base, f))
|
||||
next if self.dest.sub(/\/$/, '') == File.join(base, f)
|
||||
|
@ -129,6 +134,7 @@ module Jekyll
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Constructs a hash map of Posts indexed by the specified Post attribute
|
||||
#
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
layout: default
|
||||
title: Categories
|
||||
---
|
||||
|
||||
Categories _should_ work
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
layout: default
|
||||
title: Categories
|
||||
---
|
||||
|
||||
Categories _should_ work. Even if ordered after index.
|
|
@ -11,6 +11,7 @@ class TestGeneratedSite < Test::Unit::TestCase
|
|||
|
||||
def test_site_posts_in_index
|
||||
# confirm that {{ site.posts }} is working
|
||||
puts @s.posts.size
|
||||
assert @index.include?("#{@s.posts.size} Posts")
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue