Adding tags to the site payload. Derived mostly from Henrik's implementation in 072d9e7
This commit is contained in:
parent
99098dd8c7
commit
86b1450234
|
@ -49,3 +49,13 @@ Feature: Site data
|
||||||
When I run jekyll
|
When I run jekyll
|
||||||
Then the _site directory should exist
|
Then the _site directory should exist
|
||||||
And I should see "Awesome Hack" in "_site/index.html"
|
And I should see "Awesome Hack" in "_site/index.html"
|
||||||
|
|
||||||
|
Scenario: Use site.tags variable
|
||||||
|
Given I have a _posts directory
|
||||||
|
And I have an "index.html" page that contains "{% for post in site.tags.beer %} {{ post.content }} {% endfor %}"
|
||||||
|
And I have the following posts:
|
||||||
|
| title | date | tag | content |
|
||||||
|
| Delicious Beer | 3/26/2009 | beer | 1) Yuengling |
|
||||||
|
When I run jekyll
|
||||||
|
Then the _site directory should exist
|
||||||
|
And I should see "Yuengling" in "_site/index.html"
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
module Jekyll
|
module Jekyll
|
||||||
|
|
||||||
class Site
|
class Site
|
||||||
attr_accessor :config, :layouts, :posts, :categories, :exclude
|
attr_accessor :config, :layouts, :posts, :categories, :exclude,
|
||||||
attr_accessor :source, :dest, :lsi, :pygments, :permalink_style
|
:source, :dest, :lsi, :pygments, :permalink_style, :tags
|
||||||
|
|
||||||
# Initialize the site
|
# Initialize the site
|
||||||
# +config+ is a Hash containing site configurations details
|
# +config+ is a Hash containing site configurations details
|
||||||
|
@ -25,7 +25,8 @@ module Jekyll
|
||||||
def reset
|
def reset
|
||||||
self.layouts = {}
|
self.layouts = {}
|
||||||
self.posts = []
|
self.posts = []
|
||||||
self.categories = Hash.new { |hash, key| hash[key] = Array.new }
|
self.categories = Hash.new { |hash, key| hash[key] = [] }
|
||||||
|
self.tags = Hash.new { |hash, key| hash[key] = [] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
|
@ -126,6 +127,7 @@ module Jekyll
|
||||||
if post.published
|
if post.published
|
||||||
self.posts << post
|
self.posts << post
|
||||||
post.categories.each { |c| self.categories[c] << post }
|
post.categories.each { |c| self.categories[c] << post }
|
||||||
|
post.tags.each { |c| self.tags[c] << post }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -137,7 +139,8 @@ module Jekyll
|
||||||
post.render(self.layouts, site_payload)
|
post.render(self.layouts, site_payload)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.categories.values.map { |cats| cats.sort! { |a, b| b <=> a} }
|
self.categories.values.map { |ps| ps.sort! { |a, b| b <=> a} }
|
||||||
|
self.tags.values.map { |ps| ps.sort! { |a, b| b <=> a} }
|
||||||
rescue Errno::ENOENT => e
|
rescue Errno::ENOENT => e
|
||||||
# ignore missing layout dir
|
# ignore missing layout dir
|
||||||
end
|
end
|
||||||
|
@ -219,7 +222,8 @@ module Jekyll
|
||||||
{"site" => {
|
{"site" => {
|
||||||
"time" => Time.now,
|
"time" => Time.now,
|
||||||
"posts" => self.posts.sort { |a,b| b <=> a },
|
"posts" => self.posts.sort { |a,b| b <=> a },
|
||||||
"categories" => post_attr_hash('categories')}}
|
"categories" => post_attr_hash('categories'),
|
||||||
|
"tags" => post_attr_hash('tags')}}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Filter out any files/directories that are hidden or backup files (start
|
# Filter out any files/directories that are hidden or backup files (start
|
||||||
|
|
|
@ -9,6 +9,10 @@ class TestSite < Test::Unit::TestCase
|
||||||
@site = Site.new(Jekyll.configuration)
|
@site = Site.new(Jekyll.configuration)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "have an empty tag hash by default" do
|
||||||
|
assert_equal Hash.new, @site.tags
|
||||||
|
end
|
||||||
|
|
||||||
should "reset data before processing" do
|
should "reset data before processing" do
|
||||||
clear_dest
|
clear_dest
|
||||||
@site.process
|
@site.process
|
||||||
|
|
Loading…
Reference in New Issue