Added tags to posts. Based off Henrik's implementation in 072d9e7.

This commit is contained in:
Nick Quaranto 2009-05-18 08:58:24 -04:00
parent 921aee23d3
commit 102f6be6a2
7 changed files with 56 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 <Hash>
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

View File

@ -0,0 +1,6 @@
---
title: A Tag
tag: code
---
Whoa.

View File

@ -0,0 +1,9 @@
---
title: Some Tags
tags:
- food
- cooking
- pizza
---
Awesome!

View File

@ -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