From a56eeb828924c887b6e22d0372109b7911cfd83d Mon Sep 17 00:00:00 2001 From: Christos Trochalakis Date: Wed, 2 Jun 2010 11:37:07 +0300 Subject: [PATCH 01/18] Add support for rdiscount extensions Specify extensions at your _config.yml file: ... rdiscount: extensions: [smart, autolink] Available extensions can be found here: http://rdoc.info/projects/rtomayko/rdiscount closes #173 --- lib/jekyll.rb | 3 +++ lib/jekyll/converters/markdown.rb | 5 ++++- test/test_rdiscount.rb | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 test/test_rdiscount.rb diff --git a/lib/jekyll.rb b/lib/jekyll.rb index 9e8def36..9cd72b52 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -71,6 +71,9 @@ module Jekyll 'png_engine' => 'blahtex', 'png_dir' => 'images/latex', 'png_url' => '/images/latex' + }, + 'rdiscount' => { + 'extensions' => [] } } diff --git a/lib/jekyll/converters/markdown.rb b/lib/jekyll/converters/markdown.rb index b4bc2475..317b1487 100644 --- a/lib/jekyll/converters/markdown.rb +++ b/lib/jekyll/converters/markdown.rb @@ -13,6 +13,9 @@ module Jekyll when 'rdiscount' begin require 'rdiscount' + + # Load rdiscount extensions + @rdiscount_extensions = @config['rdiscount']['extensions'].map { |e| e.to_sym } rescue LoadError STDERR.puts 'You are missing a library required for Markdown. Please run:' STDERR.puts ' $ [sudo] gem install rdiscount' @@ -67,7 +70,7 @@ module Jekyll setup case @config['markdown'] when 'rdiscount' - RDiscount.new(content).to_html + RDiscount.new(content, *@rdiscount_extensions).to_html when 'maruku' Maruku.new(content).to_html end diff --git a/test/test_rdiscount.rb b/test/test_rdiscount.rb new file mode 100644 index 00000000..2cb40d6d --- /dev/null +++ b/test/test_rdiscount.rb @@ -0,0 +1,18 @@ +require File.dirname(__FILE__) + '/helper' + +class TestRdiscount < Test::Unit::TestCase + + context "rdiscount" do + setup do + config = { + 'rdiscount' => { 'extensions' => ['smart'] }, + 'markdown' => 'rdiscount' + } + @markdown = MarkdownConverter.new config + end + + should "pass rdiscount extensions" do + assert_equal "

“smart”

", @markdown.convert('"smart"').strip + end + end +end From d9bc00c80459409e454d4a72b477fcb75b2e22ce Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Tue, 24 Aug 2010 15:05:28 -0700 Subject: [PATCH 02/18] Highlight should not be able to render local files. --- History.txt | 4 ++++ lib/jekyll/albino.rb | 2 +- test/test_tags.rb | 14 +++++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/History.txt b/History.txt index 55aa6027..f0de13dd 100644 --- a/History.txt +++ b/History.txt @@ -1,3 +1,7 @@ +== HEAD + * Bug Fixes + * Highlight should not be able to render local files + == 0.6.2 / 2010-06-25 * Bug Fixes * Fix Rakefile 'release' task (tag pushing was missing origin) diff --git a/lib/jekyll/albino.rb b/lib/jekyll/albino.rb index 10d0ffb9..f71e6382 100644 --- a/lib/jekyll/albino.rb +++ b/lib/jekyll/albino.rb @@ -54,7 +54,7 @@ class Albino end def initialize(target, lexer = :text, format = :html) - @target = File.exists?(target) ? File.read(target) : target rescue target + @target = target @options = { :l => lexer, :f => format, :O => 'encoding=utf-8' } end diff --git a/test/test_tags.rb b/test/test_tags.rb index ac92deda..d25aa705 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -24,9 +24,7 @@ title: This is a test This document results in a markdown error with maruku -{% highlight text %} -#{code} -{% endhighlight %} +{% highlight text %}#{code}{% endhighlight %} CONTENT create_post(content, override) end @@ -45,6 +43,16 @@ CONTENT end end + context "post content has highlight with file reference" do + setup do + fill_post("./jekyll.gemspec") + end + + should "not embed the file" do + assert_match %{
./jekyll.gemspec\n
}, @result + end + end + context "post content has highlight tag with UTF character" do setup do fill_post("Æ") From f4fb833d343d1f1409f1ff0822f6f869229d13a9 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Sat, 26 Jun 2010 23:03:16 -0700 Subject: [PATCH 03/18] The site configuration may not always provide a 'time' setting. Closes #184. * This fixes a bug on Ruby 1.9.1 and 1.9.2 where Time.parse was being passed an emptry String, if the 'time' setting was not defined. --- History.txt | 1 + lib/jekyll/site.rb | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/History.txt b/History.txt index f0de13dd..ae51e1ef 100644 --- a/History.txt +++ b/History.txt @@ -1,6 +1,7 @@ == HEAD * Bug Fixes * Highlight should not be able to render local files + * The site configuration may not always provide a 'time' setting (#184) == 0.6.2 / 2010-06-25 * Bug Fixes diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 7570cb0b..d158e33b 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -28,7 +28,11 @@ module Jekyll end def reset - self.time = Time.parse(self.config['time'].to_s) || Time.now + self.time = if self.config['time'] + Time.parse(self.config['time'].to_s) + else + Time.now + end self.layouts = {} self.posts = [] self.pages = [] From 9b423a96fd85ab1a0c57c6484f46db01e8504271 Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Tue, 24 Aug 2010 15:21:47 -0700 Subject: [PATCH 04/18] Update history for ctrochalakis/rdiscount_extensions. --- History.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/History.txt b/History.txt index ae51e1ef..c40318ba 100644 --- a/History.txt +++ b/History.txt @@ -1,4 +1,6 @@ == HEAD + * Minor Enhancements + * Add support for rdiscount extensions (#173) * Bug Fixes * Highlight should not be able to render local files * The site configuration may not always provide a 'time' setting (#184) From 3fa9af17fa5449fc7f59618d429febe5a7d06fff Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Tue, 24 Aug 2010 15:35:18 -0700 Subject: [PATCH 05/18] Release 0.7.0 --- History.txt | 2 +- jekyll.gemspec | 5 +++-- lib/jekyll.rb | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/History.txt b/History.txt index c40318ba..20ce3958 100644 --- a/History.txt +++ b/History.txt @@ -1,4 +1,4 @@ -== HEAD +== 0.7.0 / 2010-08-24 * Minor Enhancements * Add support for rdiscount extensions (#173) * Bug Fixes diff --git a/jekyll.gemspec b/jekyll.gemspec index cab7dabd..b5cb0419 100644 --- a/jekyll.gemspec +++ b/jekyll.gemspec @@ -4,8 +4,8 @@ Gem::Specification.new do |s| s.rubygems_version = '1.3.5' s.name = 'jekyll' - s.version = '0.6.2' - s.date = '2010-06-25' + s.version = '0.7.0' + s.date = '2010-08-24' s.rubyforge_project = 'jekyll' s.summary = "A simple, blog aware, static site generator." @@ -123,6 +123,7 @@ Gem::Specification.new do |s| test/test_page.rb test/test_pager.rb test/test_post.rb + test/test_rdiscount.rb test/test_site.rb test/test_tags.rb ] diff --git a/lib/jekyll.rb b/lib/jekyll.rb index a91187c3..9d13f99f 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -45,7 +45,7 @@ require_all 'jekyll/generators' require_all 'jekyll/tags' module Jekyll - VERSION = '0.6.2' + VERSION = '0.7.0' # Default options. Overriden by values in _config.yml or command-line opts. # (Strings rather symbols used for compatability with YAML). From b6678d4e4310ead39310b688fb6b2dae8fc189a3 Mon Sep 17 00:00:00 2001 From: Matt Hall Date: Thu, 2 Sep 2010 13:36:31 +0100 Subject: [PATCH 06/18] Added Wordpress.com migrator --- lib/jekyll/migrators/wordpress.com.rb | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lib/jekyll/migrators/wordpress.com.rb diff --git a/lib/jekyll/migrators/wordpress.com.rb b/lib/jekyll/migrators/wordpress.com.rb new file mode 100644 index 00000000..5be1b42d --- /dev/null +++ b/lib/jekyll/migrators/wordpress.com.rb @@ -0,0 +1,38 @@ +require 'rubygems' +require 'hpricot' +require 'fileutils' + +# This importer takes a wordpress.xml file, +# which can be exported from your +# wordpress.com blog (/wp-admin/export.php) + +module Jekyll + module WordpressDotCom + def self.process(filename = "wordpress.xml") + FileUtils.mkdir_p "_posts" + posts = 0 + + doc = Hpricot::XML(File.read(filename)) + + (doc/:channel/:item).each do |item| + title = item.at(:title).inner_text + name = "#{Date.parse((doc/:channel/:item).first.at(:pubDate).inner_text).to_s("%Y-%m-%d")}-#{title.downcase.gsub('[^a-z0-9]', '-')}.html" + + File.open("_posts/#{name}", "w") do |f| + f.puts <<-HEADER +--- +layout: post +title: #{title} +--- + +HEADER + f.puts item.at('content:encoded').inner_text + end + + posts += 1 + end + + "Imported #{posts} posts" + end + end +end \ No newline at end of file From b1049c84cd369ce565ad9925ed6d53546eeca8de Mon Sep 17 00:00:00 2001 From: Leandro Lisboa Penz Date: Sun, 5 Sep 2010 18:11:09 -0300 Subject: [PATCH 07/18] Correctly generates file basename. Fixes #208. The previous procedure generated invalid basenames when the filename had more than one dot. --- History.txt | 4 ++++ lib/jekyll/page.rb | 2 +- test/source/deal.with.dots.html | 7 +++++++ test/test_page.rb | 10 ++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/source/deal.with.dots.html diff --git a/History.txt b/History.txt index 20ce3958..ba13f283 100644 --- a/History.txt +++ b/History.txt @@ -1,3 +1,7 @@ +== HEAD + * Bug Fixes + * Fixed filename basename generation (#208) + == 0.7.0 / 2010-08-24 * Minor Enhancements * Add support for rdiscount extensions (#173) diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index 3cdce5df..c4143424 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -71,7 +71,7 @@ module Jekyll # Returns nothing def process(name) self.ext = File.extname(name) - self.basename = name.split('.')[0..-2].first + self.basename = name[0 .. -self.ext.length-1] end # Add any necessary layouts to this post diff --git a/test/source/deal.with.dots.html b/test/source/deal.with.dots.html new file mode 100644 index 00000000..a69dac8c --- /dev/null +++ b/test/source/deal.with.dots.html @@ -0,0 +1,7 @@ +--- +title: Deal with dots +permalink: /deal.with.dots/ +--- + +Let's test if jekyll deals properly with dots. + diff --git a/test/test_page.rb b/test/test_page.rb index 6fbb003d..6c82fcac 100644 --- a/test/test_page.rb +++ b/test/test_page.rb @@ -23,6 +23,16 @@ class TestPage < Test::Unit::TestCase assert_equal "/contacts.html", @page.url end + should "deal properly with extensions" do + @page = setup_page('deal.with.dots.html') + assert_equal ".html", @page.ext + end + + should "deal properly with dots" do + @page = setup_page('deal.with.dots.html') + assert_equal "deal.with.dots", @page.basename + end + context "with pretty url style" do setup do @site.permalink_style = :pretty From 16c19ecd190b7cb26e4a4e4f97c204f300a3ce65 Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Thu, 9 Sep 2010 09:37:51 +0200 Subject: [PATCH 08/18] Add a failing test for rendering dotfiles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test uses a simple ".htaccess" file that needs to be rendered as any other page, like the sitemap.xml, … --- test/source/.htaccess | 8 ++++++++ test/test_page.rb | 9 +++++++++ 2 files changed, 17 insertions(+) create mode 100644 test/source/.htaccess diff --git a/test/source/.htaccess b/test/source/.htaccess new file mode 100644 index 00000000..294fb14a --- /dev/null +++ b/test/source/.htaccess @@ -0,0 +1,8 @@ +--- +layout: nil +--- +ErrorDocument 404 /404.html +ErrorDocument 500 /500.html +{% for post in site.posts %} + # {{ post.url }} +{% endfor %} \ No newline at end of file diff --git a/test/test_page.rb b/test/test_page.rb index 6fbb003d..36d38087 100644 --- a/test/test_page.rb +++ b/test/test_page.rb @@ -92,6 +92,15 @@ class TestPage < Test::Unit::TestCase assert File.directory?(dest_dir) assert File.exists?(File.join(dest_dir,'sitemap.xml')) end + + should "write dotfiles properly" do + page = setup_page('.htaccess') + do_render(page) + page.write(dest_dir) + + assert File.directory?(dest_dir) + assert File.exists?(File.join(dest_dir, '.htaccess')) + end end end From e9cf7b46368ede7dc67a5a7318323d6a73728b5b Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Thu, 9 Sep 2010 09:40:47 +0200 Subject: [PATCH 09/18] Treat dotfiles as files without extension If the file starts with a dot, the whole filename is considered the basename and there is not extension. --- lib/jekyll/page.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index 3cdce5df..16053b77 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -70,8 +70,14 @@ module Jekyll # # Returns nothing def process(name) - self.ext = File.extname(name) - self.basename = name.split('.')[0..-2].first + # Is it a dotfile ? + if name[/^\./] + self.ext = '' + self.basename = name + else + self.ext = File.extname(name) + self.basename = name.split('.')[0..-2].first + end end # Add any necessary layouts to this post From 8ecb70d3e3a9fcb2e43bf1cd8298462ba31e7336 Mon Sep 17 00:00:00 2001 From: cblunt Date: Mon, 13 Sep 2010 00:09:33 +0100 Subject: [PATCH 10/18] Added limit-posts option to site configuration. * Added unit tests for limit-posts. * Added feature for limit-posts. * Added --limit-posts option to bin/jekyll options parser --- bin/jekyll | 11 +++++++++++ features/create_sites.feature | 4 ++-- features/site_configuration.feature | 16 ++++++++++++++++ lib/jekyll/site.rb | 9 ++++++++- test/test_generated_site.rb | 28 ++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 3 deletions(-) diff --git a/bin/jekyll b/bin/jekyll index 94a5c090..f4990f5f 100755 --- a/bin/jekyll +++ b/bin/jekyll @@ -78,6 +78,17 @@ opts = OptionParser.new do |opts| end end + opts.on("--limit-posts [MAX_POSTS]", "Limit the number of posts to publish") do |limit_posts| + begin + options['limit_posts'] = limit_posts.to_i + raise ArgumentError if options['limit_posts'] < 1 + rescue + puts 'you must specify a number of posts by page bigger than 0' + exit 0 + end + end + + opts.on("--url [URL]", "Set custom site.url") do |url| options['url'] = url end diff --git a/features/create_sites.feature b/features/create_sites.feature index 8517e28d..a7b5d9b1 100644 --- a/features/create_sites.feature +++ b/features/create_sites.feature @@ -89,6 +89,6 @@ Feature: Create sites And I have an "_includes/about.textile" file that contains "Generated by {% include jekyll.textile %}" And I have an "_includes/jekyll.textile" file that contains "Jekyll" And I have an "index.html" page that contains "Basic Site with include tag: {% include about.textile %}" - When I run jekyll + When I debug jekyll Then the _site directory should exist - And I should see "Basic Site with include tag: Generated by Jekyll" in "_site/index.html" \ No newline at end of file + And I should see "Basic Site with include tag: Generated by Jekyll" in "_site/index.html" diff --git a/features/site_configuration.feature b/features/site_configuration.feature index 6f1c600e..38a315ae 100644 --- a/features/site_configuration.feature +++ b/features/site_configuration.feature @@ -101,3 +101,19 @@ Feature: Site configuration And I should see "Page Layout: 2 on 2010-01-01" in "_site/index.html" And I should see "Post Layout:

content for entry1.

" in "_site/2007/12/31/entry1.html" And I should see "Post Layout:

content for entry2.

" in "_site/2020/01/31/entry2.html" + + Scenario: Limit the number of posts generated by most recent date + Given I have a _posts directory + And I have a configuration file with: + | key | value | + | limit_posts | 2 | + And I have the following posts: + | title | date | content | + | Apples | 3/27/2009 | An article about apples | + | Oranges | 4/1/2009 | An article about oranges | + | Bananas | 4/5/2009 | An article about bananas | + When I run jekyll + Then the _site directory should exist + And the "_site/2009/04/05/bananas.html" file should exist + And the "_site/2009/04/01/oranges.html" file should exist + And the "_site/2009/03/27/apples.html" file should not exist diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index d158e33b..331b6c07 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -3,7 +3,8 @@ module Jekyll class Site attr_accessor :config, :layouts, :posts, :pages, :static_files, :categories, :exclude, :source, :dest, :lsi, :pygments, - :permalink_style, :tags, :time, :future, :safe, :plugins + :permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts + attr_accessor :converters, :generators # Initialize the site @@ -22,6 +23,7 @@ module Jekyll self.permalink_style = config['permalink'].to_sym self.exclude = config['exclude'] || [] self.future = config['future'] + self.limit_posts = config['limit_posts'] || nil self.reset self.setup @@ -39,6 +41,8 @@ module Jekyll self.static_files = [] self.categories = Hash.new { |hash, key| hash[key] = [] } self.tags = Hash.new { |hash, key| hash[key] = [] } + + raise ArgumentError, "Limit posts must be nil or >= 1" if !self.limit_posts.nil? && self.limit_posts < 1 end def setup @@ -122,6 +126,9 @@ module Jekyll end self.posts.sort! + + # limit the posts if :limit_posts option is set + self.posts = self.posts[-limit_posts, limit_posts] if limit_posts end def generate diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb index bfb86daa..cba75649 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -41,4 +41,32 @@ class TestGeneratedSite < Test::Unit::TestCase assert File.exists?(dest_dir('/contacts.html')) end end + + context "generating limited posts" do + setup do + clear_dest + stub(Jekyll).configuration do + Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 5}) + end + + @site = Site.new(Jekyll.configuration) + @site.process + @index = File.read(dest_dir('index.html')) + end + + should "generate only the specified number of posts" do + assert_equal 5, @site.posts.size + end + + should "ensure limit posts is 1 or more" do + assert_raise ArgumentError do + clear_dest + stub(Jekyll).configuration do + Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 0}) + end + + @site = Site.new(Jekyll.configuration) + end + end + end end From f688c9df81c257bd1ff7e75d1fd4c46430f2a2b9 Mon Sep 17 00:00:00 2001 From: cblunt Date: Mon, 13 Sep 2010 00:09:33 +0100 Subject: [PATCH 11/18] Added limit-posts option to site configuration. * Added unit tests for limit-posts. * Added feature for limit-posts. * Added --limit_posts option to bin/jekyll options parser --- bin/jekyll | 11 +++++++++++ features/create_sites.feature | 4 ++-- features/site_configuration.feature | 16 ++++++++++++++++ lib/jekyll/site.rb | 9 ++++++++- test/test_generated_site.rb | 28 ++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 3 deletions(-) diff --git a/bin/jekyll b/bin/jekyll index 94a5c090..9916a828 100755 --- a/bin/jekyll +++ b/bin/jekyll @@ -78,6 +78,17 @@ opts = OptionParser.new do |opts| end end + opts.on("--limit_posts [MAX_POSTS]", "Limit the number of posts to publish") do |limit_posts| + begin + options['limit_posts'] = limit_posts.to_i + raise ArgumentError if options['limit_posts'] < 1 + rescue + puts 'you must specify a number of posts by page bigger than 0' + exit 0 + end + end + + opts.on("--url [URL]", "Set custom site.url") do |url| options['url'] = url end diff --git a/features/create_sites.feature b/features/create_sites.feature index 8517e28d..a7b5d9b1 100644 --- a/features/create_sites.feature +++ b/features/create_sites.feature @@ -89,6 +89,6 @@ Feature: Create sites And I have an "_includes/about.textile" file that contains "Generated by {% include jekyll.textile %}" And I have an "_includes/jekyll.textile" file that contains "Jekyll" And I have an "index.html" page that contains "Basic Site with include tag: {% include about.textile %}" - When I run jekyll + When I debug jekyll Then the _site directory should exist - And I should see "Basic Site with include tag: Generated by Jekyll" in "_site/index.html" \ No newline at end of file + And I should see "Basic Site with include tag: Generated by Jekyll" in "_site/index.html" diff --git a/features/site_configuration.feature b/features/site_configuration.feature index 6f1c600e..38a315ae 100644 --- a/features/site_configuration.feature +++ b/features/site_configuration.feature @@ -101,3 +101,19 @@ Feature: Site configuration And I should see "Page Layout: 2 on 2010-01-01" in "_site/index.html" And I should see "Post Layout:

content for entry1.

" in "_site/2007/12/31/entry1.html" And I should see "Post Layout:

content for entry2.

" in "_site/2020/01/31/entry2.html" + + Scenario: Limit the number of posts generated by most recent date + Given I have a _posts directory + And I have a configuration file with: + | key | value | + | limit_posts | 2 | + And I have the following posts: + | title | date | content | + | Apples | 3/27/2009 | An article about apples | + | Oranges | 4/1/2009 | An article about oranges | + | Bananas | 4/5/2009 | An article about bananas | + When I run jekyll + Then the _site directory should exist + And the "_site/2009/04/05/bananas.html" file should exist + And the "_site/2009/04/01/oranges.html" file should exist + And the "_site/2009/03/27/apples.html" file should not exist diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index d158e33b..331b6c07 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -3,7 +3,8 @@ module Jekyll class Site attr_accessor :config, :layouts, :posts, :pages, :static_files, :categories, :exclude, :source, :dest, :lsi, :pygments, - :permalink_style, :tags, :time, :future, :safe, :plugins + :permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts + attr_accessor :converters, :generators # Initialize the site @@ -22,6 +23,7 @@ module Jekyll self.permalink_style = config['permalink'].to_sym self.exclude = config['exclude'] || [] self.future = config['future'] + self.limit_posts = config['limit_posts'] || nil self.reset self.setup @@ -39,6 +41,8 @@ module Jekyll self.static_files = [] self.categories = Hash.new { |hash, key| hash[key] = [] } self.tags = Hash.new { |hash, key| hash[key] = [] } + + raise ArgumentError, "Limit posts must be nil or >= 1" if !self.limit_posts.nil? && self.limit_posts < 1 end def setup @@ -122,6 +126,9 @@ module Jekyll end self.posts.sort! + + # limit the posts if :limit_posts option is set + self.posts = self.posts[-limit_posts, limit_posts] if limit_posts end def generate diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb index bfb86daa..cba75649 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -41,4 +41,32 @@ class TestGeneratedSite < Test::Unit::TestCase assert File.exists?(dest_dir('/contacts.html')) end end + + context "generating limited posts" do + setup do + clear_dest + stub(Jekyll).configuration do + Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 5}) + end + + @site = Site.new(Jekyll.configuration) + @site.process + @index = File.read(dest_dir('index.html')) + end + + should "generate only the specified number of posts" do + assert_equal 5, @site.posts.size + end + + should "ensure limit posts is 1 or more" do + assert_raise ArgumentError do + clear_dest + stub(Jekyll).configuration do + Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 0}) + end + + @site = Site.new(Jekyll.configuration) + end + end + end end From 4c08643c50a59a404faaa639b33ac6c635b678ff Mon Sep 17 00:00:00 2001 From: "Christopher H. Laco" Date: Fri, 12 Nov 2010 11:15:30 -0500 Subject: [PATCH 12/18] Added uri_escape for cases where cgi_escape isn't appropriate --- lib/jekyll/filters.rb | 6 ++++++ test/test_filters.rb | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index 5bdebec8..3356eadf 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -1,3 +1,5 @@ +require 'uri' + module Jekyll module Filters @@ -25,6 +27,10 @@ module Jekyll CGI::escape(input) end + def uri_escape(input) + URI.escape(input) + end + def number_of_words(input) input.split.length end diff --git a/test/test_filters.rb b/test/test_filters.rb index bb2d8f82..0897fbc2 100644 --- a/test/test_filters.rb +++ b/test/test_filters.rb @@ -45,5 +45,9 @@ class TestFilters < Test::Unit::TestCase should "escape special characters" do assert_equal "hey%21", @filter.cgi_escape("hey!") end + + should "escape space as %20" do + assert_equal "my%20things", @filter.uri_escape("my things") + end end end From accdb2d39fd92166676bcadc3ae9efd8adec037e Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Wed, 17 Nov 2010 12:16:15 -0600 Subject: [PATCH 13/18] Update history for wordpress.com importer. --- History.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/History.txt b/History.txt index 20ce3958..9ea28b60 100644 --- a/History.txt +++ b/History.txt @@ -1,3 +1,7 @@ +== HEAD + * Minor Enhancements + * Add wordpress.com importer (#207) + == 0.7.0 / 2010-08-24 * Minor Enhancements * Add support for rdiscount extensions (#173) From 8cc537026da0fd698afba8f1fbed423b39374e76 Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Wed, 17 Nov 2010 14:59:20 -0600 Subject: [PATCH 14/18] Update history for --limit-posts option. --- History.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/History.txt b/History.txt index 6246577f..af5632ff 100644 --- a/History.txt +++ b/History.txt @@ -1,6 +1,7 @@ == HEAD * Minor Enhancements * Add wordpress.com importer (#207) + * Add --limit-posts cli option (#212) * Bug Fixes * Fixed filename basename generation (#208) From d53ea4a0dd8affa79018d10f3869b0791df59e78 Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Wed, 17 Nov 2010 15:32:03 -0600 Subject: [PATCH 15/18] Update history for uri_escape filter. --- History.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/History.txt b/History.txt index af5632ff..ce2355dc 100644 --- a/History.txt +++ b/History.txt @@ -2,6 +2,7 @@ * Minor Enhancements * Add wordpress.com importer (#207) * Add --limit-posts cli option (#212) + * Add uri_escape filter (#234) * Bug Fixes * Fixed filename basename generation (#208) From 4a8fc1fa6e3fa5dc05c81ac5ac4ffed0b0818ac4 Mon Sep 17 00:00:00 2001 From: Arnar Birgisson Date: Wed, 17 Nov 2010 22:50:40 +0100 Subject: [PATCH 16/18] Adding baseurl option. Fixes #51 --- bin/jekyll | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/jekyll b/bin/jekyll index 9916a828..ffbe4f08 100755 --- a/bin/jekyll +++ b/bin/jekyll @@ -40,6 +40,10 @@ opts = OptionParser.new do |opts| options['server_port'] = port unless port.nil? end + opts.on("--baseurl [BASE_URL]", "Serve website from a given base URL (default '/'") do |baseurl| + options['baseurl'] = baseurl + end + opts.on("--lsi", "Use LSI for better related posts") do options['lsi'] = true end @@ -177,9 +181,9 @@ if options['server'] s = HTTPServer.new( :Port => options['server_port'], - :DocumentRoot => destination, :MimeTypes => mime_types ) + s.mount(options['baseurl'], HTTPServlet::FileHandler, destination) t = Thread.new { s.start } From 38ed81e0ce29b321186ee62a2b33310c69f32d33 Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Thu, 18 Nov 2010 00:11:04 -0600 Subject: [PATCH 17/18] Update history for --base-url option. --- History.txt | 1 + bin/jekyll | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/History.txt b/History.txt index ce2355dc..c1dd391a 100644 --- a/History.txt +++ b/History.txt @@ -3,6 +3,7 @@ * Add wordpress.com importer (#207) * Add --limit-posts cli option (#212) * Add uri_escape filter (#234) + * Add --base-url cli option (#235) * Bug Fixes * Fixed filename basename generation (#208) diff --git a/bin/jekyll b/bin/jekyll index ffbe4f08..62d88e1a 100755 --- a/bin/jekyll +++ b/bin/jekyll @@ -40,7 +40,7 @@ opts = OptionParser.new do |opts| options['server_port'] = port unless port.nil? end - opts.on("--baseurl [BASE_URL]", "Serve website from a given base URL (default '/'") do |baseurl| + opts.on("--base-url [BASE_URL]", "Serve website from a given base URL (default '/'") do |baseurl| options['baseurl'] = baseurl end @@ -92,7 +92,6 @@ opts = OptionParser.new do |opts| end end - opts.on("--url [URL]", "Set custom site.url") do |url| options['url'] = url end From 9396c9d04c9c64458dbd5348d38edcd8a8b19d17 Mon Sep 17 00:00:00 2001 From: Tomasz Stachewicz Date: Thu, 18 Nov 2010 18:14:08 +0100 Subject: [PATCH 18/18] migrators now open Sequel connection to mysql with utf8 encoding. Closes GH-220 --- lib/jekyll/migrators/mephisto.rb | 2 +- lib/jekyll/migrators/mt.rb | 2 +- lib/jekyll/migrators/textpattern.rb | 2 +- lib/jekyll/migrators/typo.rb | 2 +- lib/jekyll/migrators/wordpress.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/jekyll/migrators/mephisto.rb b/lib/jekyll/migrators/mephisto.rb index aa985b5e..9a3e33ae 100644 --- a/lib/jekyll/migrators/mephisto.rb +++ b/lib/jekyll/migrators/mephisto.rb @@ -40,7 +40,7 @@ module Jekyll QUERY = "SELECT id, permalink, body, published_at, title FROM contents WHERE user_id = 1 AND type = 'Article' AND published_at IS NOT NULL ORDER BY published_at" def self.process(dbname, user, pass, host = 'localhost') - db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host) + db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8') FileUtils.mkdir_p "_posts" diff --git a/lib/jekyll/migrators/mt.rb b/lib/jekyll/migrators/mt.rb index 27b12226..940228d5 100644 --- a/lib/jekyll/migrators/mt.rb +++ b/lib/jekyll/migrators/mt.rb @@ -20,7 +20,7 @@ module Jekyll QUERY = "SELECT entry_id, entry_basename, entry_text, entry_text_more, entry_created_on, entry_title FROM mt_entry" def self.process(dbname, user, pass, host = 'localhost') - db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host) + db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8') FileUtils.mkdir_p "_posts" diff --git a/lib/jekyll/migrators/textpattern.rb b/lib/jekyll/migrators/textpattern.rb index a9a972db..4b371197 100644 --- a/lib/jekyll/migrators/textpattern.rb +++ b/lib/jekyll/migrators/textpattern.rb @@ -17,7 +17,7 @@ module Jekyll QUERY = "select Title, url_title, Posted, Body, Keywords from textpattern where Status = '4' or Status = '5'" def self.process(dbname, user, pass, host = 'localhost') - db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host) + db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8') FileUtils.mkdir_p "_posts" diff --git a/lib/jekyll/migrators/typo.rb b/lib/jekyll/migrators/typo.rb index 23775483..1795a6bb 100644 --- a/lib/jekyll/migrators/typo.rb +++ b/lib/jekyll/migrators/typo.rb @@ -22,7 +22,7 @@ module Jekyll def self.process dbname, user, pass, host='localhost' FileUtils.mkdir_p '_posts' - db = Sequel.mysql dbname, :user => user, :password => pass, :host => host + db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8') db[SQL].each do |post| next unless post[:state] =~ /Published/ diff --git a/lib/jekyll/migrators/wordpress.rb b/lib/jekyll/migrators/wordpress.rb index bd80daee..11b4f49a 100644 --- a/lib/jekyll/migrators/wordpress.rb +++ b/lib/jekyll/migrators/wordpress.rb @@ -19,7 +19,7 @@ module Jekyll QUERY = "select post_title, post_name, post_date, post_content, post_excerpt, ID, guid from wp_posts where post_status = 'publish' and post_type = 'post'" def self.process(dbname, user, pass, host = 'localhost') - db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host) + db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8') FileUtils.mkdir_p "_posts"