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
|
Then the _site directory should exist
|
||||||
And I should see "Post category: movies" in "_site/movies/2009/03/27/star-wars.html"
|
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
|
Scenario: Use post.categories variable when categories are in folders
|
||||||
Given I have a movies directory
|
Given I have a movies directory
|
||||||
And I have a movies/scifi 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'}")
|
path = File.join(before || '.', '_posts', after || '.', "#{date}-#{title}.#{post['type'] || 'textile'}")
|
||||||
|
|
||||||
matter_hash = {}
|
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]
|
matter_hash[key] = post[key] if post[key]
|
||||||
end
|
end
|
||||||
matter = matter_hash.map { |k, v| "#{k}: #{v}\n" }.join.chomp
|
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.content = self.content[($1.size + 5)..-1]
|
||||||
|
|
||||||
self.data = YAML.load($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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ module Jekyll
|
||||||
name =~ MATCHER
|
name =~ MATCHER
|
||||||
end
|
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
|
attr_writer :categories
|
||||||
|
|
||||||
def categories
|
def categories
|
||||||
|
@ -201,14 +201,15 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns <Hash>
|
# Returns <Hash>
|
||||||
def to_liquid
|
def to_liquid
|
||||||
{ "title" => self.data["title"] || self.slug.split('-').select {|w| w.capitalize! || w }.join(' '),
|
{ "title" => self.data["title"] || self.slug.split('-').select {|w| w.capitalize! || w }.join(' '),
|
||||||
"url" => self.url,
|
"url" => self.url,
|
||||||
"date" => self.date,
|
"date" => self.date,
|
||||||
"id" => self.id,
|
"id" => self.id,
|
||||||
"categories" => self.categories,
|
"categories" => self.categories,
|
||||||
"next" => self.next,
|
"next" => self.next,
|
||||||
"previous" => self.previous,
|
"previous" => self.previous,
|
||||||
"content" => self.content }.deep_merge(self.data)
|
"tags" => self.tags,
|
||||||
|
"content" => self.content }.deep_merge(self.data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
|
|
|
@ -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')
|
assert post.categories.include?('baz')
|
||||||
end
|
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
|
context "rendering" do
|
||||||
setup do
|
setup do
|
||||||
clear_dest
|
clear_dest
|
||||||
|
|
Loading…
Reference in New Issue