class Jekyll::LunrJsSearch::SearchEntry

Attributes

body[R]
categories[R]
collection[R]
date[R]
is_post[R]
tags[R]
title[R]
url[R]

Public Class Methods

create(site, renderer) click to toggle source
# File lib/jekyll_lunr_js_search/search_entry.rb, line 6
def self.create(site, renderer)
  if site.is_a?(Jekyll::Page) or site.is_a?(Jekyll::Document)
    if defined?(site.date)
      date = site.date
    else
      date = nil
    end
    categories = site.data['categories']
    tags = site.data['tags']
    title, url = extract_title_and_url(site)
    is_post = site.is_a?(Jekyll::Document)
    body = renderer.render(site)

    SearchEntry.new(title, url, date, categories, tags, is_post, body, renderer)
  else
    raise 'Not supported'
  end
end
extract_title_and_url(item) click to toggle source
# File lib/jekyll_lunr_js_search/search_entry.rb, line 25
def self.extract_title_and_url(item)
  data = item.to_liquid
  [ data['title'], data['url'] ]
end
new(title, url, date, categories, tags, is_post, body, collection) click to toggle source
# File lib/jekyll_lunr_js_search/search_entry.rb, line 32
def initialize(title, url, date, categories, tags, is_post, body, collection)
  @title, @url, @date, @categories, @tags, @is_post, @body, @collection = title, url, date, categories, tags, is_post, body, collection
end

Public Instance Methods

strip_index_suffix_from_url!() click to toggle source
# File lib/jekyll_lunr_js_search/search_entry.rb, line 36
def strip_index_suffix_from_url!
  @url.gsub!(/index\.html$/, '')
end
strip_stopwords!(stopwords, min_length) click to toggle source

remove anything that is in the stop words list from the text to be indexed

# File lib/jekyll_lunr_js_search/search_entry.rb, line 41
def strip_stopwords!(stopwords, min_length)
  @body = @body.split.delete_if() do |x|
    t = x.downcase.gsub(/[^a-z]/, '')
    t.length < min_length || stopwords.include?(t)
  end.join(' ')
end