From 23031152359e2f963fbef5908c470dda05493d00 Mon Sep 17 00:00:00 2001 From: Nick Quaranto Date: Tue, 27 Jan 2009 17:11:26 -0500 Subject: [PATCH 1/7] Making rake test happy on 1.8.7 --- test/test_generated_site.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb index 24e5ef1a..56e5e422 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -11,7 +11,6 @@ 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 From 4bcfaeae69bc560a8278c201c313a466e512c429 Mon Sep 17 00:00:00 2001 From: Nick Quaranto Date: Tue, 27 Jan 2009 17:38:35 -0500 Subject: [PATCH 2/7] Starting on yaml categories --- test/source/_posts/2009-01-27-categories.textile | 7 +++++++ test/source/_posts/2009-01-27-category.textile | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 test/source/_posts/2009-01-27-categories.textile create mode 100644 test/source/_posts/2009-01-27-category.textile diff --git a/test/source/_posts/2009-01-27-categories.textile b/test/source/_posts/2009-01-27-categories.textile new file mode 100644 index 00000000..189fe29f --- /dev/null +++ b/test/source/_posts/2009-01-27-categories.textile @@ -0,0 +1,7 @@ +--- +layout: default +title: Categories in YAML +categories: foo bar baz +--- + +Best *post* ever diff --git a/test/source/_posts/2009-01-27-category.textile b/test/source/_posts/2009-01-27-category.textile new file mode 100644 index 00000000..2881e4c9 --- /dev/null +++ b/test/source/_posts/2009-01-27-category.textile @@ -0,0 +1,7 @@ +--- +layout: default +title: Category in YAML +category: foo +--- + +Best *post* ever From 1211f23b53af69f5ce31bd1e7eec747294f12e78 Mon Sep 17 00:00:00 2001 From: Nick Quaranto Date: Wed, 28 Jan 2009 09:22:46 -0500 Subject: [PATCH 3/7] Adding support for setting post categories through YAML if not specified by directory structure --- .gitignore | 2 ++ lib/jekyll/post.rb | 8 ++++++++ test/helper.rb | 3 ++- test/test_generated_site.rb | 10 +++++++--- test/test_post.rb | 14 +++++++++++++- test/test_site.rb | 17 ++++++++++------- 6 files changed, 42 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 92e4ce11..de43f334 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ test/dest/ *.gem pkg/ +*.swp +*~ diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 07068184..81213b3f 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -38,6 +38,14 @@ module Jekyll self.process(name) self.read_yaml(@base, name) + + if self.categories.empty? + if self.data.has_key?('category') + self.categories << self.data['category'] + elsif self.data.has_key?('categories') + self.categories = self.data['categories'].split + end + end end # Spaceship is based on Post#date diff --git a/test/helper.rb b/test/helper.rb index 9aabcdd2..611d6d60 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -1,6 +1,7 @@ require File.join(File.dirname(__FILE__), *%w[.. lib jekyll]) require 'test/unit' +require 'redgreen' include Jekyll @@ -10,4 +11,4 @@ end def clear_dest FileUtils.rm_rf(dest_dir) -end \ No newline at end of file +end diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb index 56e5e422..373545d4 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -3,8 +3,8 @@ 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) + @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 @@ -16,6 +16,10 @@ class TestGeneratedSite < Test::Unit::TestCase def test_post_content_in_index # confirm that the {{ post.content }} is rendered OK - assert @index.include?('

This is cool

') + latest_post = Dir[File.join(@source, '_posts/*')].last + post = Post.new(@source, '', File.basename(latest_post)) + Jekyll.content_type = post.determine_content_type + post.transform + assert @index.include?(post.content) end end diff --git a/test/test_post.rb b/test/test_post.rb index 713eec02..202ea55f 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -70,6 +70,18 @@ class TestPost < Test::Unit::TestCase assert_equal "

{{ page.title }}

\n

Best post ever

", p.content end + + def test_yaml_category + p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2009-01-27-category.textile") + assert p.categories.include?('foo') + end + + def test_yaml_categories + p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2009-01-27-categories.textile") + assert p.categories.include?('foo') + assert p.categories.include?('bar') + assert p.categories.include?('baz') + end def test_render p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2008-10-18-foo-bar.textile") @@ -110,4 +122,4 @@ class TestPost < Test::Unit::TestCase assert_equal "<<<
\n

Tom Preston-Werner github.com/mojombo

\n\n

This is cool

>>>", p.output end -end \ No newline at end of file +end diff --git a/test/test_site.rb b/test/test_site.rb index 03bf1669..7bcf6dee 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -2,8 +2,8 @@ require File.dirname(__FILE__) + '/helper' class TestSite < Test::Unit::TestCase def setup - source = File.join(File.dirname(__FILE__), *%w[source]) - @s = Site.new(source, dest_dir) + @source = File.join(File.dirname(__FILE__), *%w[source]) + @s = Site.new(@source, dest_dir) end def test_site_init @@ -18,16 +18,19 @@ class TestSite < Test::Unit::TestCase def test_read_posts @s.read_posts('') - - assert_equal 4, @s.posts.size + posts = Dir[File.join(@source, '_posts/*')] + assert_equal posts.size, @s.posts.size end def test_site_payload clear_dest @s.process - assert_equal 7, @s.posts.length - assert_equal ["category", "foo", "z_category"].sort, @s.categories.keys.sort - assert_equal 1, @s.categories['foo'].length + posts = Dir[File.join(@source, "**", "_posts/*")] + categories = %w(bar baz category foo z_category).sort + + assert_equal posts.size, @s.posts.size + assert_equal categories, @s.categories.keys.sort + assert_equal 3, @s.categories['foo'].size end end From ad617da4e0b7d1d1e5c7157b26eb1e8d0dcaaecb Mon Sep 17 00:00:00 2001 From: Nick Quaranto Date: Mon, 2 Feb 2009 22:24:51 -0500 Subject: [PATCH 4/7] Added publish flag to posts, not preventing it from being in the destination directory yet. --- lib/jekyll/post.rb | 8 +++++++- .../_posts/2008-02-02-not-published.textile | 7 +++++++ .../publish_test/_posts/2008-02-02-publish.textile | 7 +++++++ test/test_post.rb | 10 ++++++++++ test/test_site.rb | 2 +- 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 test/source/publish_test/_posts/2008-02-02-not-published.textile create mode 100644 test/source/publish_test/_posts/2008-02-02-publish.textile diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 81213b3f..0e2af904 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -18,7 +18,7 @@ module Jekyll name =~ MATCHER end - attr_accessor :date, :slug, :ext, :categories, :topics + attr_accessor :date, :slug, :ext, :categories, :topics, :published attr_accessor :data, :content, :output # Initialize this Post instance. @@ -38,6 +38,12 @@ module Jekyll self.process(name) self.read_yaml(@base, name) + + if self.data.has_key?('published') && self.data['published'] == false + self.published = false + else + self.published = true + end if self.categories.empty? if self.data.has_key?('category') diff --git a/test/source/publish_test/_posts/2008-02-02-not-published.textile b/test/source/publish_test/_posts/2008-02-02-not-published.textile new file mode 100644 index 00000000..265b6062 --- /dev/null +++ b/test/source/publish_test/_posts/2008-02-02-not-published.textile @@ -0,0 +1,7 @@ +--- +layout: default +title: Not published! +published: false +--- + +This should *not* be published! diff --git a/test/source/publish_test/_posts/2008-02-02-publish.textile b/test/source/publish_test/_posts/2008-02-02-publish.textile new file mode 100644 index 00000000..5fac7557 --- /dev/null +++ b/test/source/publish_test/_posts/2008-02-02-publish.textile @@ -0,0 +1,7 @@ +--- +layout: default +title: Publish +--- + +This should be published. + diff --git a/test/test_post.rb b/test/test_post.rb index 202ea55f..449e5f19 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -71,6 +71,16 @@ class TestPost < Test::Unit::TestCase assert_equal "

{{ page.title }}

\n

Best post ever

", p.content end + def test_published + p = Post.new(File.join(File.dirname(__FILE__), *%w[source publish_test]), '', "2008-02-02-publish.textile") + assert_equal true, p.published + end + + def test_not_published + p = Post.new(File.join(File.dirname(__FILE__), *%w[source publish_test]), '', "2008-02-02-not-published.textile") + assert_equal false, p.published + end + def test_yaml_category p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2009-01-27-category.textile") assert p.categories.include?('foo') diff --git a/test/test_site.rb b/test/test_site.rb index 7bcf6dee..4ffb4cdb 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -27,7 +27,7 @@ class TestSite < Test::Unit::TestCase @s.process posts = Dir[File.join(@source, "**", "_posts/*")] - categories = %w(bar baz category foo z_category).sort + categories = %w(bar baz category foo z_category publish_test).sort assert_equal posts.size, @s.posts.size assert_equal categories, @s.categories.keys.sort From efdd5ef395fd9544e9bb3270b7d4ff2a9f4f81f9 Mon Sep 17 00:00:00 2001 From: Nick Quaranto Date: Mon, 2 Feb 2009 22:52:19 -0500 Subject: [PATCH 5/7] Making sure that posts flagged as published: false don't get rendered or copied. --- lib/jekyll/site.rb | 7 +++++-- .../_posts/2008-02-02-not-published.textile | 1 + .../2008-02-02-published.textile} | 1 + test/test_generated_site.rb | 7 +++++++ test/test_post.rb | 4 ++-- test/test_site.rb | 4 ++-- 6 files changed, 18 insertions(+), 6 deletions(-) rename test/source/{publish_test => }/_posts/2008-02-02-not-published.textile (80%) rename test/source/{publish_test/_posts/2008-02-02-publish.textile => _posts/2008-02-02-published.textile} (74%) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 187effbe..9b96ee6e 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -63,8 +63,11 @@ module Jekyll entries.each do |f| if Post.valid?(f) post = Post.new(self.source, dir, f) - self.posts << post - post.categories.each { |c| self.categories[c] << post } + + if post.published + self.posts << post + post.categories.each { |c| self.categories[c] << post } + end end end diff --git a/test/source/publish_test/_posts/2008-02-02-not-published.textile b/test/source/_posts/2008-02-02-not-published.textile similarity index 80% rename from test/source/publish_test/_posts/2008-02-02-not-published.textile rename to test/source/_posts/2008-02-02-not-published.textile index 265b6062..5ff418dc 100644 --- a/test/source/publish_test/_posts/2008-02-02-not-published.textile +++ b/test/source/_posts/2008-02-02-not-published.textile @@ -2,6 +2,7 @@ layout: default title: Not published! published: false +category: publish_test --- This should *not* be published! diff --git a/test/source/publish_test/_posts/2008-02-02-publish.textile b/test/source/_posts/2008-02-02-published.textile similarity index 74% rename from test/source/publish_test/_posts/2008-02-02-publish.textile rename to test/source/_posts/2008-02-02-published.textile index 5fac7557..78651408 100644 --- a/test/source/publish_test/_posts/2008-02-02-publish.textile +++ b/test/source/_posts/2008-02-02-published.textile @@ -1,6 +1,7 @@ --- layout: default title: Publish +category: publish_test --- This should be published. diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb index 373545d4..0762d299 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -22,4 +22,11 @@ class TestGeneratedSite < Test::Unit::TestCase post.transform assert @index.include?(post.content) end + + def test_unpublished_posts_are_hidden + published = Dir[File.join(dest_dir, 'publish_test/2008/02/02/*.html')].map {|f| File.basename(f)} + + assert_equal 1, published.size + assert_equal "published.html", published.first + end end diff --git a/test/test_post.rb b/test/test_post.rb index 449e5f19..0a118df3 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -72,12 +72,12 @@ class TestPost < Test::Unit::TestCase end def test_published - p = Post.new(File.join(File.dirname(__FILE__), *%w[source publish_test]), '', "2008-02-02-publish.textile") + p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2008-02-02-published.textile") assert_equal true, p.published end def test_not_published - p = Post.new(File.join(File.dirname(__FILE__), *%w[source publish_test]), '', "2008-02-02-not-published.textile") + p = Post.new(File.join(File.dirname(__FILE__), *%w[source]), '', "2008-02-02-not-published.textile") assert_equal false, p.published end diff --git a/test/test_site.rb b/test/test_site.rb index 4ffb4cdb..e19eefcd 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -19,7 +19,7 @@ class TestSite < Test::Unit::TestCase def test_read_posts @s.read_posts('') posts = Dir[File.join(@source, '_posts/*')] - assert_equal posts.size, @s.posts.size + assert_equal posts.size - 1, @s.posts.size end def test_site_payload @@ -29,7 +29,7 @@ class TestSite < Test::Unit::TestCase posts = Dir[File.join(@source, "**", "_posts/*")] categories = %w(bar baz category foo z_category publish_test).sort - assert_equal posts.size, @s.posts.size + assert_equal posts.size - 1, @s.posts.size assert_equal categories, @s.categories.keys.sort assert_equal 3, @s.categories['foo'].size end From 45b33f7b96678bbbbd01133688548a0bc8bcdb65 Mon Sep 17 00:00:00 2001 From: Nick Quaranto Date: Tue, 10 Feb 2009 01:27:13 -0500 Subject: [PATCH 6/7] Adding explanations for new YAML front matter options --- README.textile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.textile b/README.textile index c08efb6b..35c98daf 100644 --- a/README.textile +++ b/README.textile @@ -255,6 +255,15 @@ h3. Predefined Post Variables /year/month/day/title.html then you can set this variable and it will be used as the final URL. + published + Set to false if you don't want a post to show up when the site is + generated. + + category/categories + Instead of placing posts inside of folders, you can specify one or more + categories that the post belongs to. When the site is generated the post + will act as though it had been set with these categories normally. + h3. Custom Variables Any variables in the front matter that are not predefined are mixed into the From 60709da7067fbe1d106fbdfadb3a84b35d07d721 Mon Sep 17 00:00:00 2001 From: Nick Quaranto Date: Tue, 10 Feb 2009 01:38:09 -0500 Subject: [PATCH 7/7] Removing some bad formatting in the README --- README.textile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.textile b/README.textile index 35c98daf..0ed13e8f 100644 --- a/README.textile +++ b/README.textile @@ -256,13 +256,13 @@ h3. Predefined Post Variables be used as the final URL. published - Set to false if you don't want a post to show up when the site is - generated. + Set to false if you don't want a post to show up when the site is + generated. - category/categories - Instead of placing posts inside of folders, you can specify one or more - categories that the post belongs to. When the site is generated the post - will act as though it had been set with these categories normally. + category/categories + Instead of placing posts inside of folders, you can specify one or more + categories that the post belongs to. When the site is generated the post + will act as though it had been set with these categories normally. h3. Custom Variables @@ -381,7 +381,7 @@ within a Liquid template as follows:
 {% for post in site.categories.foo %}
-	
  • {{ post.date | date_to_string }} - {{ post.title }}
  • +
  • {{ post.date | date_to_string }} - {{ post.title }}
  • {% endfor %}