Refactor Post#related_posts to build the index in a different method

This commit is contained in:
Parker Moore 2013-04-26 20:05:52 +02:00
parent ffa93c22f1
commit 09c1c01d07
1 changed files with 14 additions and 10 deletions

View File

@ -229,6 +229,16 @@ module Jekyll
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)
@ -239,12 +249,6 @@ module Jekyll
puts ""
lsi
end
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.