diff --git a/History.txt b/History.txt index 947f56c8..e4b7dacf 100644 --- a/History.txt +++ b/History.txt @@ -4,7 +4,6 @@ * Minor Enhancements * Added post categories based on directories containing _posts [github.com/mreid] * Added new date filter that shows the full month name [github.com/mreid] - * Make post's YAML front matter available as post.data [github.com/remi] * Merge Post's YAML front matter into its to_liquid payload [github.com/remi] * Restrict includes to regular files underneath _includes * Bug Fixes diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 433c754a..0a74fc23 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -54,7 +54,12 @@ module Jekyll entries = entries.reject { |e| File.directory?(e) } entries.each do |f| - self.posts << Post.new(base, f) if Post.valid?(f) + if Post.valid?(f) + post = Post.new(base, f) + post.content = Liquid::Template.parse(post.content).render(site_payload, [Jekyll::Filters]) + post.transform + self.posts << post + end end self.posts.sort! @@ -86,10 +91,15 @@ module Jekyll (e != '_posts') and ['.', '_'].include?(e[0..0]) } + # we need to make sure to process _posts *first* otherwise they + # might not be available yet to other templates as {{ site.posts }} + if entries.include? '_posts' + entries.delete '_posts' + read_posts(File.join(base, '_posts')) + end + entries.each do |f| - if f == '_posts' - read_posts(File.join(base, f)) - elsif File.directory?(File.join(base, f)) + if File.directory?(File.join(base, f)) next if self.dest.sub(/\/$/, '') == File.join(base, f) transform_pages(File.join(dir, f)) else diff --git a/test/source/index.html b/test/source/index.html index b3cc7556..493fce7c 100644 --- a/test/source/index.html +++ b/test/source/index.html @@ -5,8 +5,18 @@ title: Tom Preston-Werner h1. Welcome to my site +h2. Please read our {{ site.posts | size }} Posts + \ No newline at end of file + + +{% assign first_post = site.posts.first %} +
+

{{ first_post.title }}

+
+ {{ first_post.content }} +
+
diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb new file mode 100644 index 00000000..56e5e422 --- /dev/null +++ b/test/test_generated_site.rb @@ -0,0 +1,21 @@ +require File.dirname(__FILE__) + '/helper' + +class TestGeneratedSite < Test::Unit::TestCase + def setup + clear_dest + source = File.join(File.dirname(__FILE__), *%w[source]) + @s = Site.new(source, dest_dir) + @s.process + @index = File.read(File.join(dest_dir, 'index.html')) + end + + def test_site_posts_in_index + # confirm that {{ site.posts }} is working + assert @index.include?("#{@s.posts.size} Posts") + end + + def test_post_content_in_index + # confirm that the {{ post.content }} is rendered OK + assert @index.include?('

This is cool

') + end +end diff --git a/test/test_site.rb b/test/test_site.rb index ccfd4117..bde6a008 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -27,4 +27,4 @@ class TestSite < Test::Unit::TestCase @s.process end -end \ No newline at end of file +end