Added tags to posts. Based off Henrik's implementation in 072d9e7.
This commit is contained in:
parent
921aee23d3
commit
102f6be6a2
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -208,6 +208,7 @@ module Jekyll
|
|||
"categories" => self.categories,
|
||||
"next" => self.next,
|
||||
"previous" => self.previous,
|
||||
"tags" => self.tags,
|
||||
"content" => self.content }.deep_merge(self.data)
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
title: A Tag
|
||||
tag: code
|
||||
---
|
||||
|
||||
Whoa.
|
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
title: Some Tags
|
||||
tags:
|
||||
- food
|
||||
- cooking
|
||||
- pizza
|
||||
---
|
||||
|
||||
Awesome!
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue