Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adding tags to the site payload. Derived mostly from Henrik's impleme…

…ntation in 072d9e7
  • Loading branch information...
commit 86b1450234be7b4a530629124800edcdf9e78bfe 1 parent 99098dd
Nick Quaranto qrush authored
10 features/site_data.feature
@@ -49,3 +49,13 @@ Feature: Site data
49 49 When I run jekyll
50 50 Then the _site directory should exist
51 51 And I should see "Awesome Hack" in "_site/index.html"
  52 +
  53 + Scenario: Use site.tags variable
  54 + Given I have a _posts directory
  55 + And I have an "index.html" page that contains "{% for post in site.tags.beer %} {{ post.content }} {% endfor %}"
  56 + And I have the following posts:
  57 + | title | date | tag | content |
  58 + | Delicious Beer | 3/26/2009 | beer | 1) Yuengling |
  59 + When I run jekyll
  60 + Then the _site directory should exist
  61 + And I should see "Yuengling" in "_site/index.html"
14 lib/jekyll/site.rb
... ... @@ -1,8 +1,8 @@
1 1 module Jekyll
2 2
3 3 class Site
4   - attr_accessor :config, :layouts, :posts, :categories, :exclude
5   - attr_accessor :source, :dest, :lsi, :pygments, :permalink_style
  4 + attr_accessor :config, :layouts, :posts, :categories, :exclude,
  5 + :source, :dest, :lsi, :pygments, :permalink_style, :tags
6 6
7 7 # Initialize the site
8 8 # +config+ is a Hash containing site configurations details
@@ -25,7 +25,8 @@ def initialize(config)
25 25 def reset
26 26 self.layouts = {}
27 27 self.posts = []
28   - self.categories = Hash.new { |hash, key| hash[key] = Array.new }
  28 + self.categories = Hash.new { |hash, key| hash[key] = [] }
  29 + self.tags = Hash.new { |hash, key| hash[key] = [] }
29 30 end
30 31
31 32 def setup
@@ -126,6 +127,7 @@ def read_posts(dir)
126 127 if post.published
127 128 self.posts << post
128 129 post.categories.each { |c| self.categories[c] << post }
  130 + post.tags.each { |c| self.tags[c] << post }
129 131 end
130 132 end
131 133 end
@@ -137,7 +139,8 @@ def read_posts(dir)
137 139 post.render(self.layouts, site_payload)
138 140 end
139 141
140   - self.categories.values.map { |cats| cats.sort! { |a, b| b <=> a} }
  142 + self.categories.values.map { |ps| ps.sort! { |a, b| b <=> a} }
  143 + self.tags.values.map { |ps| ps.sort! { |a, b| b <=> a} }
141 144 rescue Errno::ENOENT => e
142 145 # ignore missing layout dir
143 146 end
@@ -219,7 +222,8 @@ def site_payload
219 222 {"site" => {
220 223 "time" => Time.now,
221 224 "posts" => self.posts.sort { |a,b| b <=> a },
222   - "categories" => post_attr_hash('categories')}}
  225 + "categories" => post_attr_hash('categories'),
  226 + "tags" => post_attr_hash('tags')}}
223 227 end
224 228
225 229 # Filter out any files/directories that are hidden or backup files (start
4 test/test_site.rb
@@ -9,6 +9,10 @@ class TestSite < Test::Unit::TestCase
9 9 @site = Site.new(Jekyll.configuration)
10 10 end
11 11
  12 + should "have an empty tag hash by default" do
  13 + assert_equal Hash.new, @site.tags
  14 + end
  15 +
12 16 should "reset data before processing" do
13 17 clear_dest
14 18 @site.process

0 comments on commit 86b1450

Please sign in to comment.
Something went wrong with that request. Please try again.