Class: Jekyll::RelatedPosts
- Inherits:
-
Object
- Object
- Jekyll::RelatedPosts
- Defined in:
- lib/jekyll/related_posts.rb
Class Attribute Summary collapse
-
.lsi ⇒ Object
Returns the value of attribute lsi.
Instance Attribute Summary collapse
-
#post ⇒ Object
readonly
Returns the value of attribute post.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
- #build ⇒ Object
- #build_index ⇒ Object
- #display(output) ⇒ Object
-
#initialize(post) ⇒ RelatedPosts
constructor
A new instance of RelatedPosts.
- #lsi_related_posts ⇒ Object
- #most_recent_posts ⇒ Object
Constructor Details
#initialize(post) ⇒ RelatedPosts
Returns a new instance of RelatedPosts.
9 10 11 12 13 |
# File 'lib/jekyll/related_posts.rb', line 9 def initialize(post) @post = post @site = post.site Jekyll::External.require_with_graceful_fail('classifier-reborn') if site.lsi end |
Class Attribute Details
.lsi ⇒ Object
Returns the value of attribute lsi.
4 5 6 |
# File 'lib/jekyll/related_posts.rb', line 4 def lsi @lsi end |
Instance Attribute Details
#post ⇒ Object (readonly)
Returns the value of attribute post.
7 8 9 |
# File 'lib/jekyll/related_posts.rb', line 7 def post @post end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
7 8 9 |
# File 'lib/jekyll/related_posts.rb', line 7 def site @site end |
Instance Method Details
#build ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/jekyll/related_posts.rb', line 15 def build return [] unless site.posts.docs.size > 1 if site.lsi build_index else most_recent_posts end end |
#build_index ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jekyll/related_posts.rb', line 26 def build_index self.class.lsi ||= begin lsi = ClassifierReborn::LSI.new(:auto_rebuild => false) display("Populating LSI...") site.posts.docs.each do |x| lsi.add_item(x) end display("Rebuilding index...") lsi.build_index display("") lsi end end |
#display(output) ⇒ Object
50 51 52 53 54 |
# File 'lib/jekyll/related_posts.rb', line 50 def display(output) $stdout.print("\n") $stdout.print(Jekyll.logger.formatted_topic(output)) $stdout.flush end |
#lsi_related_posts ⇒ Object
42 43 44 |
# File 'lib/jekyll/related_posts.rb', line 42 def self.class.lsi.(post, 11) end |
#most_recent_posts ⇒ Object
46 47 48 |
# File 'lib/jekyll/related_posts.rb', line 46 def most_recent_posts @most_recent_posts ||= (site.posts.docs.reverse - [post]).first(10) end |