Sha256: 67cfc9f7dec85f6839ef8062f791d491e3d93ccd110a004ac725e43e2646495a
Contents?: true
Size: 1.08 KB
Versions: 5
Compression:
Stored size: 1.08 KB
Contents
module Jekyll class RelatedPosts class << self attr_accessor :lsi end attr_reader :post, :site def initialize(post) @post = post @site = post.site require 'classifier-reborn' if site.lsi end def build return [] unless site.posts.size > 1 if site.lsi build_index lsi_related_posts else most_recent_posts end end def build_index self.class.lsi ||= begin lsi = ClassifierReborn::LSI.new(:auto_rebuild => false) display("Populating LSI...") site.posts.each do |x| lsi.add_item(x) end display("Rebuilding index...") lsi.build_index display("") lsi end end def lsi_related_posts self.class.lsi.find_related(post.content, 11) - [post] end def most_recent_posts @most_recent_posts ||= (site.posts.reverse - [post]).first(10) end def display(output) $stdout.print("\n") $stdout.print(Jekyll.logger.formatted_topic(output)) $stdout.flush end end end
Version data entries
5 entries across 5 versions & 1 rubygems