lib/jekyll/post.rb in jekyll-0.1.4 vs lib/jekyll/post.rb in jekyll-0.1.5

- old
+ new

@@ -94,20 +94,26 @@ # Calculate related posts. # # Returns [<Post>] def related_posts(posts) - self.class.lsi ||= begin - puts "Running the classifier... this could take a while." - lsi = Classifier::LSI.new - posts.each { |x| $stdout.print(".");$stdout.flush;lsi.add_item(x) } - puts "" - lsi - end + return [] unless posts.size > 1 + + if Jekyll.lsi + self.class.lsi ||= begin + puts "Running the classifier... this could take a while." + lsi = Classifier::LSI.new + posts.each { |x| $stdout.print(".");$stdout.flush;lsi.add_item(x) } + puts "" + lsi + end - related = self.class.lsi.find_related(self.content, 11) - related - [self] + related = self.class.lsi.find_related(self.content, 11) + related - [self] + else + (posts - [self])[0..9] + end end # Add any necessary layouts to this post # +layouts+ is a Hash of {"name" => "layout"} # +site_payload+ is the site payload hash @@ -143,6 +149,6 @@ "id" => self.id, "content" => self.content } end end -end \ No newline at end of file +end