diff --git a/features/post_data.feature b/features/post_data.feature index 93ec0a94..87f5d851 100644 --- a/features/post_data.feature +++ b/features/post_data.feature @@ -70,6 +70,17 @@ Feature: Post data Then the _site directory should exist And I should see "Post category: movies" in "_site/movies/2009/03/27/star-wars.html" + Scenario: Use post.tags variable + Given I have a _posts directory + And I have a _layouts directory + And I have the following post: + | title | date | layout | tag | content | + | Star Wars | 5/18/2009 | simple | twist | Luke, I am your father. | + And I have a simple layout that contains "Post tags: {{ site.posts.first.tags }}" + When I run jekyll + Then the _site directory should exist + And I should see "Post tags: twist" in "_site/2009/05/18/star-wars.html" + Scenario: Use post.categories variable when categories are in folders Given I have a movies directory And I have a movies/scifi directory diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 49a16132..3bf34736 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -57,7 +57,7 @@ Given /^I have the following posts?(?: (.*) "(.*)")?:$/ do |direction, folder, t path = File.join(before || '.', '_posts', after || '.', "#{date}-#{title}.#{post['type'] || 'textile'}") matter_hash = {} - %w(title layout tags category categories published author).each do |key| + %w(title layout tag tags category categories published author).each do |key| matter_hash[key] = post[key] if post[key] end matter = matter_hash.map { |k, v| "#{k}: #{v}\n" }.join.chomp diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index 4d2ec17f..3b8d08b1 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -22,6 +22,14 @@ module Jekyll self.content = self.content[($1.size + 5)..-1] self.data = YAML.load($1) + + if self.data.has_key?("tag") + self.tags = [self.data["tag"]] + elsif self.data.has_key?("tags") + self.tags = self.data['tags'] + else + self.tags = [] + end end end diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 61bfc8e2..b8595146 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -18,7 +18,7 @@ module Jekyll name =~ MATCHER end - attr_accessor :site, :date, :slug, :ext, :published, :data, :content, :output + attr_accessor :site, :date, :slug, :ext, :published, :data, :content, :output, :tags attr_writer :categories def categories @@ -201,14 +201,15 @@ module Jekyll # # Returns def to_liquid - { "title" => self.data["title"] || self.slug.split('-').select {|w| w.capitalize! || w }.join(' '), - "url" => self.url, - "date" => self.date, - "id" => self.id, + { "title" => self.data["title"] || self.slug.split('-').select {|w| w.capitalize! || w }.join(' '), + "url" => self.url, + "date" => self.date, + "id" => self.id, "categories" => self.categories, - "next" => self.next, - "previous" => self.previous, - "content" => self.content }.deep_merge(self.data) + "next" => self.next, + "previous" => self.previous, + "tags" => self.tags, + "content" => self.content }.deep_merge(self.data) end def inspect diff --git a/test/source/_posts/2009-05-18-tag.textile b/test/source/_posts/2009-05-18-tag.textile new file mode 100644 index 00000000..349a0093 --- /dev/null +++ b/test/source/_posts/2009-05-18-tag.textile @@ -0,0 +1,6 @@ +--- +title: A Tag +tag: code +--- + +Whoa. diff --git a/test/source/_posts/2009-05-18-tags.textile b/test/source/_posts/2009-05-18-tags.textile new file mode 100644 index 00000000..d646ad23 --- /dev/null +++ b/test/source/_posts/2009-05-18-tags.textile @@ -0,0 +1,9 @@ +--- +title: Some Tags +tags: +- food +- cooking +- pizza +--- + +Awesome! diff --git a/test/test_post.rb b/test/test_post.rb index e39f7b6e..b6585cc0 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -211,6 +211,18 @@ class TestPost < Test::Unit::TestCase assert post.categories.include?('baz') end + should "recognize tag in yaml" do + post = setup_post("2009-05-18-tag.textile") + assert post.tags.include?('code') + end + + should "recognize tags in yaml" do + post = setup_post("2009-05-18-tags.textile") + assert post.tags.include?('food') + assert post.tags.include?('cooking') + assert post.tags.include?('pizza') + end + context "rendering" do setup do clear_dest