class Jekyll::J1LunrSearch::SearchEntry

noinspection RubyTooManyInstanceVariablesInspection

Attributes

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

Public Class Methods

create(site, renderer) click to toggle source
# File lib/starter_web/_plugins/lunr_index.rb, line 279
def self.create(site, renderer)
  if site.is_a?(Jekyll::Page) or site.is_a?(Jekyll::Document)

    if defined?(site.date)
      date = site.date
    elsif defined?(site.data['date'])
      date = site.data['date']
    else
      date = '2021-01-01 00:00:00'
    end

    tagline     = site.data['tagline']
    tags        = site.data['tags']
    categories  = site.data['categories']
    description = site.data['description']
    title, url  = extract_title_and_url(site)
    is_post     = site.is_a?(Jekyll::Document)
    body        = renderer.render(site)

    if description.nil? || description.length == 0
      description = 'No description available.'
    end

    if site.is_a?(Jekyll::Document)
      excerpt = extract_excerpt(site)
      unless excerpt.nil? || excerpt.length == 0
        description = excerpt
      end
    end

    SearchEntry.new(title, tagline, url, date, tags, categories, description, is_post, body, renderer)
  else
    raise 'Not supported'
  end
end
extract_excerpt(item) click to toggle source
# File lib/starter_web/_plugins/lunr_index.rb, line 320
def self.extract_excerpt(item)
  data = item.to_liquid
  parsed_data = Nokogiri::HTML.parse(data['excerpt']).text
  parsed_data.gsub!(/\n+/, ' ')
  parsed_data.gsub!(/^\s+/, '')
  parsed_data.gsub!(/\s+$/, '')
end
extract_title_and_url(item) click to toggle source
# File lib/starter_web/_plugins/lunr_index.rb, line 315
def self.extract_title_and_url(item)
  data = item.to_liquid
  [ data['title'], data['url'] ]
end
new(title, tagline, url, date, tags, categories, description, is_post, body, collection) click to toggle source
# File lib/starter_web/_plugins/lunr_index.rb, line 330
def initialize(title, tagline, url, date, tags, categories, description, is_post, body, collection)
  @title, @tagline, @url, @date,@tags,  @categories, @description, @is_post, @body, @collection = title, tagline, url, date, tags, categories, description, is_post, body, collection
end

Public Instance Methods

strip_index_suffix_from_url!() click to toggle source
# File lib/starter_web/_plugins/lunr_index.rb, line 334
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/starter_web/_plugins/lunr_index.rb, line 341
def strip_stopwords!(stopwords, min_length)
  #noinspection RubyParenthesesAfterMethodCallInspection
  @body = @body.split.delete_if() do |x|
    t = x.downcase.gsub(/[^a-z]/, '')
    t.length < min_length || stopwords.include?(t)
  end.join(' ')
end