From f67f7f3db43e64c9fc174d3a8e6e6651cffe93f8 Mon Sep 17 00:00:00 2001 From: Matt Rogers Date: Tue, 7 May 2013 22:27:38 -0500 Subject: [PATCH 01/68] Move the building of related posts into their own class --- lib/jekyll/post.rb | 26 ++-------------- lib/jekyll/related_posts.rb | 59 +++++++++++++++++++++++++++++++++++++ lib/jekyll/site.rb | 2 -- 3 files changed, 62 insertions(+), 25 deletions(-) create mode 100644 lib/jekyll/related_posts.rb diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 571d854d..287bade0 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -1,3 +1,5 @@ +require 'jekyll/related_posts' + module Jekyll class Post include Comparable @@ -244,29 +246,7 @@ module Jekyll # # Returns an Array of related Posts. def related_posts(posts) - return [] unless posts.size > 1 - - if self.site.lsi - build_index - - related = self.class.lsi.find_related(self.content, 11) - related - [self] - else - (posts - [self])[0..9] - end - end - - def build_index - self.class.lsi ||= begin - puts "Starting the classifier..." - lsi = Classifier::LSI.new(:auto_rebuild => false) - $stdout.print(" Populating LSI... "); $stdout.flush - self.site.posts.each { |x| $stdout.print("."); $stdout.flush; lsi.add_item(x) } - $stdout.print("\n Rebuilding LSI index... ") - lsi.build_index - puts "" - lsi - end + Jekyll::RelatedPosts.new(self).build end # Add any necessary layouts to this post. diff --git a/lib/jekyll/related_posts.rb b/lib/jekyll/related_posts.rb new file mode 100644 index 00000000..7c5a597d --- /dev/null +++ b/lib/jekyll/related_posts.rb @@ -0,0 +1,59 @@ +module Jekyll + class RelatedPosts + + class << self + attr_accessor :lsi + end + + attr_reader :post, :site + + def initialize(post) + @post = post + @site = post.site + require 'classifier' if site.lsi + end + + def build + return [] unless self.site.posts.size > 1 + + if self.site.lsi + build_index + lsi_related_posts + else + most_recent_posts + end + end + + def build_index + self.class.lsi ||= begin + puts "Starting the classifier..." + lsi = Classifier::LSI.new(:auto_rebuild => false) + display(" Populating LSI... ") + + self.site.posts.each do |x| + display(".") + lsi.add_item(x) + end + + display("\n Rebuilding LSI index... ") + lsi.build_index + puts "" + lsi + end + end + + def lsi_related_posts + lsi.find_related(post.content, 11) - [self.post] + end + + def most_recent_posts + (self.site.posts - [self.post])[0..9] + end + + def display(output) + $stdout.print(output) + $stdout.flush + end + + end +end diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index d8a36e1b..f9b223fd 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -71,8 +71,6 @@ module Jekyll # # Returns nothing. def setup - require 'classifier' if self.lsi - # Check that the destination dir isn't the source dir or a directory # parent to the source dir. if self.source =~ /^#{self.dest}/ From 09fafd641898e7c26d1c9b4b5e77052a1f800b74 Mon Sep 17 00:00:00 2001 From: Christopher Giroir Date: Tue, 7 May 2013 23:24:10 -0700 Subject: [PATCH 02/68] Fixing paginate_path on windows --- lib/jekyll/generators/pagination.rb | 5 +++-- test/test_pager.rb | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/generators/pagination.rb b/lib/jekyll/generators/pagination.rb index 0cd934c5..cfcd9c30 100644 --- a/lib/jekyll/generators/pagination.rb +++ b/lib/jekyll/generators/pagination.rb @@ -92,8 +92,9 @@ module Jekyll # Returns the pagination path as a string def self.paginate_path(site_config, num_page) return nil if num_page.nil? || num_page <= 1 - format = File.basename(site_config['paginate_path']) - format.sub(':num', num_page.to_s) + format = site_config['paginate_path'] + format = format.sub(':num', num_page.to_s) + File.basename(format) end # Initialize a new Pager. diff --git a/test/test_pager.rb b/test/test_pager.rb index 7e153ea4..608a78d1 100644 --- a/test/test_pager.rb +++ b/test/test_pager.rb @@ -11,6 +11,11 @@ class TestPager < Test::Unit::TestCase assert_equal(3, Pager.calculate_pages([1,2,3,4,5], '2')) end + should "determine the pagination path" do + assert_nil(Pager.paginate_path(Jekyll::Configuration::DEFAULTS, 1)) + assert_equal("page2", Pager.paginate_path(Jekyll::Configuration::DEFAULTS, 2)) + end + context "pagination disabled" do setup do stub(Jekyll).configuration do From 64f8a7b2289c17f8de1bf6e091d94580857cca48 Mon Sep 17 00:00:00 2001 From: Matt Rogers Date: Wed, 8 May 2013 07:39:00 -0500 Subject: [PATCH 03/68] Move the require for related_posts to jekyll.rb --- lib/jekyll.rb | 1 + lib/jekyll/post.rb | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/jekyll.rb b/lib/jekyll.rb index 4f3bc1cc..0728a8b5 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -40,6 +40,7 @@ require 'jekyll/draft' require 'jekyll/filters' require 'jekyll/static_file' require 'jekyll/errors' +require 'jekyll/related_posts' # extensions require 'jekyll/plugin' diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 287bade0..c5f5dc5e 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -1,5 +1,3 @@ -require 'jekyll/related_posts' - module Jekyll class Post include Comparable From b0c04c89f44a92161becf86f9614ce074b3811b1 Mon Sep 17 00:00:00 2001 From: Christopher Giroir Date: Wed, 8 May 2013 14:08:03 -0700 Subject: [PATCH 04/68] Further clarify what paginate_path should do in the case of directories in the path --- test/test_pager.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_pager.rb b/test/test_pager.rb index 608a78d1..990d28eb 100644 --- a/test/test_pager.rb +++ b/test/test_pager.rb @@ -14,6 +14,8 @@ class TestPager < Test::Unit::TestCase should "determine the pagination path" do assert_nil(Pager.paginate_path(Jekyll::Configuration::DEFAULTS, 1)) assert_equal("page2", Pager.paginate_path(Jekyll::Configuration::DEFAULTS, 2)) + assert_nil(Pager.paginate_path(Jekyll::Configuration::DEFAULTS.merge('paginate_path' => '/blog/page-:num'), 1)) + assert_equal("page-2", Pager.paginate_path(Jekyll::Configuration::DEFAULTS.merge('paginate_path' => '/blog/page-:num'), 2)) end context "pagination disabled" do From 1aa49fa734c38c42ec14a1847ab9319e8ede3adc Mon Sep 17 00:00:00 2001 From: Matt Rogers Date: Wed, 8 May 2013 21:57:10 -0500 Subject: [PATCH 05/68] Wrap tests around Jekyll::RelatedPosts This gives me more confidence that we're doing the right things when it comes to both the LSI and non-LSI cases and prevents regressions. --- test/test_related_posts.rb | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/test_related_posts.rb diff --git a/test/test_related_posts.rb b/test/test_related_posts.rb new file mode 100644 index 00000000..cff43362 --- /dev/null +++ b/test/test_related_posts.rb @@ -0,0 +1,40 @@ +require 'helper' + +class TestRelatedPosts < Test::Unit::TestCase + context "building related posts without lsi" do + setup do + stub(Jekyll).configuration do + Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, + 'destination' => dest_dir}) + end + @site = Site.new(Jekyll.configuration) + end + + should "use the most recent posts for related posts" do + @site.reset + @site.read + assert_equal @site.posts[0..9], Jekyll::RelatedPosts.new(@site.posts.last).build + end + end + + context "building related posts with lsi" do + setup do + stub(Jekyll).configuration do + Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, + 'destination' => dest_dir, + 'lsi' => true}) + end + @site = Site.new(Jekyll.configuration) + end + + should "use lsi for the related posts" do + @site.reset + @site.read + require 'classifier' + any_instance_of(::Classifier::LSI) do |c| + stub(c).find_related { @site.posts[-1..-9] } + end + assert_equal @site.posts[-1..-9], Jekyll::RelatedPosts.new(@site.posts.last).build + end + end +end From 08b49ec9db3d814dc84f4b397741f2799b042c82 Mon Sep 17 00:00:00 2001 From: Matt Rogers Date: Wed, 8 May 2013 22:02:23 -0500 Subject: [PATCH 06/68] Update the display of the LSI progress output It now fits more in line with what the other messages display. --- lib/jekyll/related_posts.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/jekyll/related_posts.rb b/lib/jekyll/related_posts.rb index 7c5a597d..ab13a968 100644 --- a/lib/jekyll/related_posts.rb +++ b/lib/jekyll/related_posts.rb @@ -24,26 +24,25 @@ module Jekyll end end + def build_index self.class.lsi ||= begin - puts "Starting the classifier..." lsi = Classifier::LSI.new(:auto_rebuild => false) - display(" Populating LSI... ") + display("\n Populating LSI... ") self.site.posts.each do |x| - display(".") lsi.add_item(x) end - display("\n Rebuilding LSI index... ") + display("\nRebuilding index... ") lsi.build_index - puts "" + display("") lsi end end def lsi_related_posts - lsi.find_related(post.content, 11) - [self.post] + self.class.lsi.find_related(post.content, 11) - [self.post] end def most_recent_posts @@ -54,6 +53,5 @@ module Jekyll $stdout.print(output) $stdout.flush end - end end From 770402d91269a4e6271582bbef98bd762fc8e260 Mon Sep 17 00:00:00 2001 From: Matt Rogers Date: Wed, 8 May 2013 22:33:20 -0500 Subject: [PATCH 07/68] Also stub the building of the index Since we don't actually use the index in getting the related posts from the tests there's no need to build an index, which can take a long time if the ruby bindings for the GSL library are not installed. --- test/test_related_posts.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_related_posts.rb b/test/test_related_posts.rb index cff43362..98833f2f 100644 --- a/test/test_related_posts.rb +++ b/test/test_related_posts.rb @@ -33,6 +33,7 @@ class TestRelatedPosts < Test::Unit::TestCase require 'classifier' any_instance_of(::Classifier::LSI) do |c| stub(c).find_related { @site.posts[-1..-9] } + stub(c).build_index end assert_equal @site.posts[-1..-9], Jekyll::RelatedPosts.new(@site.posts.last).build end From 1646c223c4fa035d79753258c91116866c6e2101 Mon Sep 17 00:00:00 2001 From: Rusty Geldmacher Date: Thu, 9 May 2013 10:09:12 -0400 Subject: [PATCH 08/68] Added jekyll-contentblocks to the plugins list --- site/_posts/2012-07-01-plugins.md | 1 + 1 file changed, 1 insertion(+) diff --git a/site/_posts/2012-07-01-plugins.md b/site/_posts/2012-07-01-plugins.md index 52229a0e..d73b0276 100644 --- a/site/_posts/2012-07-01-plugins.md +++ b/site/_posts/2012-07-01-plugins.md @@ -403,6 +403,7 @@ There are a few useful, prebuilt plugins at the following locations: - [jekyll-rendering](https://github.com/blackwinter/jekyll-rendering): Jekyll plugin to provide alternative rendering engines. - [jekyll-pagination](https://github.com/blackwinter/jekyll-pagination): Jekyll plugin to extend the pagination generator. - [jekyll-tagging](https://github.com/pattex/jekyll-tagging): Jekyll plugin to automatically generate a tag cloud and tag pages. +- [jekyll-contentblocks](https://github.com/rustygeldmacher/jekyll-contentblocks): Lets you use Rails-like content_for tags in your templates, for passing content from your posts up to your layouts. - [Generate YouTube Embed (tag)](https://gist.github.com/1805814) by [joelverhagen](https://github.com/joelverhagen): Jekyll plugin which allows you to embed a YouTube video in your page with the YouTube ID. Optionally specify width and height dimensions. Like “oEmbed Tag” but just for YouTube. - [JSON Filter](https://gist.github.com/1850654) by [joelverhagen](https://github.com/joelverhagen): filter that takes input text and outputs it as JSON. Great for rendering JavaScript. - [jekyll-beastiepress](https://github.com/okeeblow/jekyll-beastiepress): FreeBSD utility tags for Jekyll sites. From f1c5579c5b2043448f75c86e1e56bd9c28118b12 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 12 May 2013 17:54:15 +0200 Subject: [PATCH 09/68] Add docs for post excerpt #1072 --- History.markdown | 1 + site/docs/posts.md | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/History.markdown b/History.markdown index 8dbe1ccf..6e9f8041 100644 --- a/History.markdown +++ b/History.markdown @@ -6,6 +6,7 @@ ### Bug Fixes ### Site Enhancements + * Add docs for post excerpt (#1072) * Add docs for gist tag (#1072) ### Development Fixes diff --git a/site/docs/posts.md b/site/docs/posts.md index 2eaa1566..9ad420d2 100644 --- a/site/docs/posts.md +++ b/site/docs/posts.md @@ -113,6 +113,28 @@ Of course, you have full control over how (and where) you display your posts, and how you structure your site. You should read more about [how templates work](../templates) with Jekyll if you want to know more. +## Post excerpts + +Posts automatically take the first block of text, from the beginning of the content +to the first occurrence of `excerpt_separator`, and sets it as the `post.excerpt`. +Take the above example of an index of posts for example. Maybe you want to include +a little hint about the post's content by adding the first paragraph of each of your +posts: + +{% highlight html %} + +{% endhighlight %} + +If you don't like the automatically-generated post excerpt, it can be overridden by adding +`excerpt` to your post's YAML front-matter. + ## Highlighting code snippets Jekyll also has built-in support for syntax highlighting of code snippets using From 6aaf631fcf06251b9417ea7e43c1dafd093205e1 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 12 May 2013 23:18:25 +0200 Subject: [PATCH 10/68] Fix some language problems, props @maul-esel --- site/docs/posts.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site/docs/posts.md b/site/docs/posts.md index 9ad420d2..a03d9350 100644 --- a/site/docs/posts.md +++ b/site/docs/posts.md @@ -116,8 +116,8 @@ work](../templates) with Jekyll if you want to know more. ## Post excerpts Posts automatically take the first block of text, from the beginning of the content -to the first occurrence of `excerpt_separator`, and sets it as the `post.excerpt`. -Take the above example of an index of posts for example. Maybe you want to include +to the first occurrence of `excerpt_separator`, and set it as the `post.excerpt`. +Take the above example of an index of posts. Perhaps you want to include a little hint about the post's content by adding the first paragraph of each of your posts: From d99b4324e70760d09cfe3ae537cf849f113f92b1 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 12 May 2013 23:19:38 +0200 Subject: [PATCH 11/68] When talking about post excerpts, be singular about it. --- site/docs/posts.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site/docs/posts.md b/site/docs/posts.md index a03d9350..f465a131 100644 --- a/site/docs/posts.md +++ b/site/docs/posts.md @@ -115,8 +115,8 @@ work](../templates) with Jekyll if you want to know more. ## Post excerpts -Posts automatically take the first block of text, from the beginning of the content -to the first occurrence of `excerpt_separator`, and set it as the `post.excerpt`. +Each post automatically takes the first block of text, from the beginning of the content +to the first occurrence of `excerpt_separator`, and sets it as the `post.excerpt`. Take the above example of an index of posts. Perhaps you want to include a little hint about the post's content by adding the first paragraph of each of your posts: From 47e1a449e10b4c4aa1d677718111b4dcfcd71638 Mon Sep 17 00:00:00 2001 From: David Briggs Date: Tue, 14 May 2013 00:12:48 -0400 Subject: [PATCH 12/68] fix upgrade docs --- site/docs/upgrading.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site/docs/upgrading.md b/site/docs/upgrading.md index cea5a923..0999ce01 100644 --- a/site/docs/upgrading.md +++ b/site/docs/upgrading.md @@ -40,8 +40,8 @@ Until v1.1, it is **opt-in**. Starting with v1.1, however, absolute permalinks will become **opt-out**, meaning Jekyll will default to using absolute permalinks instead of relative permalinks. -* To use absolute permalinks, set `relative_permalinks: true` in your configuration file. -* To continue using relative permalinks, set `relative_permalinks: false` in your configuration file. +* To use absolute permalinks, set `relative_permalinks: false` in your configuration file. +* To continue using relative permalinks, set `relative_permalinks: true` in your configuration file.