added support for consistent site.time in payload, generating the site at a specific time and limiting future posts
squish
This commit is contained in:
parent
a4f3f5c583
commit
98fa570c86
12
bin/jekyll
12
bin/jekyll
|
@ -48,6 +48,18 @@ opts = OptionParser.new do |opts|
|
||||||
options['markdown'] = 'rdiscount'
|
options['markdown'] = 'rdiscount'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opts.on("--time [TIME]", "Time to generate the site for") do |time|
|
||||||
|
options['time'] = Time.parse(time)
|
||||||
|
end
|
||||||
|
|
||||||
|
opts.on("--future", "Render future dated posts") do
|
||||||
|
options['future'] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
opts.on("--no-future", "Do not render future dated posts") do
|
||||||
|
options['future'] = false
|
||||||
|
end
|
||||||
|
|
||||||
opts.on("--permalink [TYPE]", "Use 'date' (default) for YYYY/MM/DD") do |style|
|
opts.on("--permalink [TYPE]", "Use 'date' (default) for YYYY/MM/DD") do |style|
|
||||||
options['permalink'] = style unless style.nil?
|
options['permalink'] = style unless style.nil?
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,7 +33,7 @@ Feature: Site configuration
|
||||||
And I have an "README" file that contains "I want to be excluded"
|
And I have an "README" file that contains "I want to be excluded"
|
||||||
And I have an "index.html" file that contains "I want to be included"
|
And I have an "index.html" file that contains "I want to be included"
|
||||||
And I have a configuration file with "exclude" set to:
|
And I have a configuration file with "exclude" set to:
|
||||||
| Value |
|
| value |
|
||||||
| README |
|
| README |
|
||||||
| Rakefile |
|
| Rakefile |
|
||||||
When I run jekyll
|
When I run jekyll
|
||||||
|
@ -61,3 +61,43 @@ Feature: Site configuration
|
||||||
When I run jekyll
|
When I run jekyll
|
||||||
Then the _site directory should exist
|
Then the _site directory should exist
|
||||||
And I should see "puts 'Hello world!'" in "_site/index.html"
|
And I should see "puts 'Hello world!'" in "_site/index.html"
|
||||||
|
|
||||||
|
Scenario: Set time and no future dated posts
|
||||||
|
Given I have a _layouts directory
|
||||||
|
And I have a page layout that contains "Page Layout: {{ site.posts.size }} on {{ site.time | date: "%Y-%m-%d" }}"
|
||||||
|
And I have a post layout that contains "Post Layout: {{ content }}"
|
||||||
|
And I have an "index.html" page with layout "page" that contains "site index page"
|
||||||
|
And I have a configuration file with:
|
||||||
|
| key | value |
|
||||||
|
| time | 2010-01-01 |
|
||||||
|
| future | false |
|
||||||
|
And I have a _posts directory
|
||||||
|
And I have the following posts:
|
||||||
|
| title | date | layout | content |
|
||||||
|
| entry1 | 12/31/2007 | post | content for entry1. |
|
||||||
|
| entry2 | 01/31/2020 | post | content for entry2. |
|
||||||
|
When I run jekyll
|
||||||
|
Then the _site directory should exist
|
||||||
|
And I should see "Page Layout: 1 on 2010-01-01" in "_site/index.html"
|
||||||
|
And I should see "Post Layout: <p>content for entry1.</p>" in "_site/2007/12/31/entry1.html"
|
||||||
|
And the "_site/2020/01/31/entry2.html" file should not exist
|
||||||
|
|
||||||
|
Scenario: Set time and future dated posts allowed
|
||||||
|
Given I have a _layouts directory
|
||||||
|
And I have a page layout that contains "Page Layout: {{ site.posts.size }} on {{ site.time | date: "%Y-%m-%d" }}"
|
||||||
|
And I have a post layout that contains "Post Layout: {{ content }}"
|
||||||
|
And I have an "index.html" page with layout "page" that contains "site index page"
|
||||||
|
And I have a configuration file with:
|
||||||
|
| key | value |
|
||||||
|
| time | 2010-01-01 |
|
||||||
|
| future | true |
|
||||||
|
And I have a _posts directory
|
||||||
|
And I have the following posts:
|
||||||
|
| title | date | layout | content |
|
||||||
|
| entry1 | 12/31/2007 | post | content for entry1. |
|
||||||
|
| entry2 | 01/31/2020 | post | content for entry2. |
|
||||||
|
When I run jekyll
|
||||||
|
Then the _site directory should exist
|
||||||
|
And I should see "Page Layout: 2 on 2010-01-01" in "_site/index.html"
|
||||||
|
And I should see "Post Layout: <p>content for entry1.</p>" in "_site/2007/12/31/entry1.html"
|
||||||
|
And I should see "Post Layout: <p>content for entry2.</p>" in "_site/2020/01/31/entry2.html"
|
||||||
|
|
|
@ -81,7 +81,16 @@ end
|
||||||
|
|
||||||
Given /^I have a configuration file with "(.*)" set to "(.*)"$/ do |key, value|
|
Given /^I have a configuration file with "(.*)" set to "(.*)"$/ do |key, value|
|
||||||
File.open('_config.yml', 'w') do |f|
|
File.open('_config.yml', 'w') do |f|
|
||||||
f.write("#{key}: #{value}")
|
f.write("#{key}: #{value}\n")
|
||||||
|
f.close
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Given /^I have a configuration file with:$/ do |table|
|
||||||
|
File.open('_config.yml', 'w') do |f|
|
||||||
|
table.hashes.each do |row|
|
||||||
|
f.write("#{row["key"]}: #{row["value"]}\n")
|
||||||
|
end
|
||||||
f.close
|
f.close
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -90,7 +99,7 @@ Given /^I have a configuration file with "([^\"]*)" set to:$/ do |key, table|
|
||||||
File.open('_config.yml', 'w') do |f|
|
File.open('_config.yml', 'w') do |f|
|
||||||
f.write("#{key}:\n")
|
f.write("#{key}:\n")
|
||||||
table.hashes.each do |row|
|
table.hashes.each do |row|
|
||||||
f.write("- #{row["Value"]}\n")
|
f.write("- #{row["value"]}\n")
|
||||||
end
|
end
|
||||||
f.close
|
f.close
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,6 +39,7 @@ module Jekyll
|
||||||
'source' => '.',
|
'source' => '.',
|
||||||
'destination' => File.join('.', '_site'),
|
'destination' => File.join('.', '_site'),
|
||||||
|
|
||||||
|
'future' => true,
|
||||||
'lsi' => false,
|
'lsi' => false,
|
||||||
'pygments' => false,
|
'pygments' => false,
|
||||||
'markdown' => 'maruku',
|
'markdown' => 'maruku',
|
||||||
|
|
|
@ -2,7 +2,8 @@ module Jekyll
|
||||||
|
|
||||||
class Site
|
class Site
|
||||||
attr_accessor :config, :layouts, :posts, :pages, :static_files, :categories, :exclude,
|
attr_accessor :config, :layouts, :posts, :pages, :static_files, :categories, :exclude,
|
||||||
:source, :dest, :lsi, :pygments, :permalink_style, :tags
|
:source, :dest, :lsi, :pygments, :permalink_style, :tags, :time,
|
||||||
|
:future
|
||||||
|
|
||||||
# Initialize the site
|
# Initialize the site
|
||||||
# +config+ is a Hash containing site configurations details
|
# +config+ is a Hash containing site configurations details
|
||||||
|
@ -17,12 +18,14 @@ module Jekyll
|
||||||
self.pygments = config['pygments']
|
self.pygments = config['pygments']
|
||||||
self.permalink_style = config['permalink'].to_sym
|
self.permalink_style = config['permalink'].to_sym
|
||||||
self.exclude = config['exclude'] || []
|
self.exclude = config['exclude'] || []
|
||||||
|
self.future = config['future']
|
||||||
|
|
||||||
self.reset
|
self.reset
|
||||||
self.setup
|
self.setup
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset
|
def reset
|
||||||
|
self.time = Time.parse(self.config['time'].to_s) || Time.now
|
||||||
self.layouts = {}
|
self.layouts = {}
|
||||||
self.posts = []
|
self.posts = []
|
||||||
self.pages = []
|
self.pages = []
|
||||||
|
@ -135,7 +138,7 @@ module Jekyll
|
||||||
if Post.valid?(f)
|
if Post.valid?(f)
|
||||||
post = Post.new(self, self.source, dir, f)
|
post = Post.new(self, self.source, dir, f)
|
||||||
|
|
||||||
if post.published
|
if post.published && (self.future || post.date <= self.time)
|
||||||
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 }
|
post.tags.each { |c| self.tags[c] << post }
|
||||||
|
@ -230,7 +233,7 @@ module Jekyll
|
||||||
# "categories" => [<Post>]}
|
# "categories" => [<Post>]}
|
||||||
def site_payload
|
def site_payload
|
||||||
{"site" => self.config.merge({
|
{"site" => self.config.merge({
|
||||||
"time" => Time.now,
|
"time" => self.time,
|
||||||
"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')})}
|
"tags" => post_attr_hash('tags')})}
|
||||||
|
|
|
@ -22,6 +22,7 @@ class TestSite < Test::Unit::TestCase
|
||||||
before_tags = @site.tags.length
|
before_tags = @site.tags.length
|
||||||
before_pages = @site.pages.length
|
before_pages = @site.pages.length
|
||||||
before_static_files = @site.static_files.length
|
before_static_files = @site.static_files.length
|
||||||
|
before_time = @site.time
|
||||||
|
|
||||||
@site.process
|
@site.process
|
||||||
assert_equal before_posts, @site.posts.length
|
assert_equal before_posts, @site.posts.length
|
||||||
|
@ -30,6 +31,7 @@ class TestSite < Test::Unit::TestCase
|
||||||
assert_equal before_tags, @site.tags.length
|
assert_equal before_tags, @site.tags.length
|
||||||
assert_equal before_pages, @site.pages.length
|
assert_equal before_pages, @site.pages.length
|
||||||
assert_equal before_static_files, @site.static_files.length
|
assert_equal before_static_files, @site.static_files.length
|
||||||
|
assert before_time <= @site.time
|
||||||
end
|
end
|
||||||
|
|
||||||
should "read layouts" do
|
should "read layouts" do
|
||||||
|
|
Loading…
Reference in New Issue