Class: Jekyll::RelatedPosts

### Home Classes Methods

### In Files

- lib/jekyll/related_posts.rb

### Parent

Object

### Methods

- ::new
- #build
- #build_index
- #display
- #lsi_related_posts
- #most_recent_posts

### Files

- LICENSE

### Class/Module Index

Quicksearch

- Jekyll
- Jekyll::Command
- Jekyll::Commands
- Jekyll::Commands::Build
- Jekyll::Commands::Doctor
- Jekyll::Commands::New
- Jekyll::Commands::Serve
- Jekyll::Configuration
- Jekyll::Converter
- Jekyll::Converters
- Jekyll::Converters::Identity
- Jekyll::Converters::Markdown
- Jekyll::Converters::Markdown::KramdownParser
- Jekyll::Converters::Markdown::MarukuParser
- Jekyll::Converters::Markdown::RDiscountParser
- Jekyll::Converters::Markdown::RedcarpetParser
- Jekyll::Converters::Markdown::RedcarpetParser::CommonMethods
- Jekyll::Converters::Markdown::RedcarpetParser::WithPygments
- Jekyll::Converters::Markdown::RedcarpetParser::WithoutPygments
- Jekyll::Converters::Textile
- Jekyll::Convertible
- Jekyll::Deprecator
- Jekyll::Draft
- Jekyll::Excerpt
- Jekyll::FatalException
- Jekyll::Filters
- Jekyll::Generator
- Jekyll::Generators
- Jekyll::Generators::Pagination
- Jekyll::GistTag
- Jekyll::Layout
- Jekyll::Page
- Jekyll::Pager
- Jekyll::Plugin
- Jekyll::Post
- Jekyll::RelatedPosts
- Jekyll::Site
- Jekyll::Site::Cleaner
- Jekyll::StaticFile
- Jekyll::Stevenson
- Jekyll::Tags
- Jekyll::Tags::HighlightBlock
- Jekyll::Tags::IncludeTag
- Jekyll::Tags::PostComparer
- Jekyll::Tags::PostUrl
- Jekyll::URL
- Date
- Enumerable
- Hash
- Object

No matching classes.

# Jekyll::RelatedPosts

### Attributes

lsi[RW]
post[R]
site[R]

### Public Class Methods

new(post) click to toggle source

    # File lib/jekyll/related_posts.rb, line 10
    def initialize(post)
      @post = post
      @site = post.site
      require 'classifier' if site.lsi
    end

### Public Instance Methods

build() click to toggle source

    # File lib/jekyll/related_posts.rb, line 16
    def build
      return [] unless self.site.posts.size > 1

      if self.site.lsi
        build_index
        lsi_related_posts
      else
        most_recent_posts
      end
    end

build_index() click to toggle source

    # File lib/jekyll/related_posts.rb, line 28
    def build_index
      self.class.lsi ||= begin
        lsi = Classifier::LSI.new(:auto_rebuild => false)
        display("Populating LSI...")

        self.site.posts.each do |x|
          lsi.add_item(x)
        end

        display("Rebuilding index...")
        lsi.build_index
        display("")
        lsi
      end
    end

display(output) click to toggle source

    # File lib/jekyll/related_posts.rb, line 53
    def display(output)
      $stdout.print("\n")
      $stdout.print(Jekyll.logger.formatted_topic(output))
      $stdout.flush
    end

lsi_related_posts() click to toggle source

    # File lib/jekyll/related_posts.rb, line 44
    def lsi_related_posts
      self.class.lsi.find_related(post.content, 11) - [self.post]
    end

most_recent_posts() click to toggle source

    # File lib/jekyll/related_posts.rb, line 48
    def most_recent_posts
      recent_posts = self.site.posts.reverse - [self.post]
      recent_posts.first(10)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.