Class: Jekyll::J1LunrSearch::SearchEntry
- Inherits:
-
Object
- Object
- Jekyll::J1LunrSearch::SearchEntry
- Defined in:
- lib/starter_web/_plugins/lunr_index.rb
Overview
noinspection RubyTooManyInstanceVariablesInspection
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#is_post ⇒ Object
readonly
Returns the value of attribute is_post.
-
#tagline ⇒ Object
readonly
Returns the value of attribute tagline.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
- .create(site, renderer) ⇒ Object
- .extract_excerpt(item) ⇒ Object
- .extract_title_and_url(item) ⇒ Object
Instance Method Summary collapse
-
#initialize(title, tagline, url, date, tags, categories, description, is_post, body, collection) ⇒ SearchEntry
constructor
A new instance of SearchEntry.
- #strip_index_suffix_from_url! ⇒ Object
-
#strip_stopwords!(stopwords, min_length) ⇒ Object
remove anything that is in the stop words list from the text to be indexed.
Constructor Details
#initialize(title, tagline, url, date, tags, categories, description, is_post, body, collection) ⇒ SearchEntry
Returns a new instance of SearchEntry.
311 312 313 |
# File 'lib/starter_web/_plugins/lunr_index.rb', line 311 def initialize(title, tagline, url, date, , categories, description, is_post, body, collection) @title, @tagline, @url, @date,@tags, @categories, @description, @is_post, @body, @collection = title, tagline, url, date, , categories, description, is_post, body, collection end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
309 310 311 |
# File 'lib/starter_web/_plugins/lunr_index.rb', line 309 def body @body end |
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
309 310 311 |
# File 'lib/starter_web/_plugins/lunr_index.rb', line 309 def categories @categories end |
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
309 310 311 |
# File 'lib/starter_web/_plugins/lunr_index.rb', line 309 def collection @collection end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
309 310 311 |
# File 'lib/starter_web/_plugins/lunr_index.rb', line 309 def date @date end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
309 310 311 |
# File 'lib/starter_web/_plugins/lunr_index.rb', line 309 def description @description end |
#is_post ⇒ Object (readonly)
Returns the value of attribute is_post.
309 310 311 |
# File 'lib/starter_web/_plugins/lunr_index.rb', line 309 def is_post @is_post end |
#tagline ⇒ Object (readonly)
Returns the value of attribute tagline.
309 310 311 |
# File 'lib/starter_web/_plugins/lunr_index.rb', line 309 def tagline @tagline end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
309 310 311 |
# File 'lib/starter_web/_plugins/lunr_index.rb', line 309 def @tags end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
309 310 311 |
# File 'lib/starter_web/_plugins/lunr_index.rb', line 309 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
309 310 311 |
# File 'lib/starter_web/_plugins/lunr_index.rb', line 309 def url @url end |
Class Method Details
.create(site, renderer) ⇒ Object
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/starter_web/_plugins/lunr_index.rb', line 260 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'] = 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, , categories, description, is_post, body, renderer) else raise 'Not supported' end end |
.extract_excerpt(item) ⇒ Object
301 302 303 304 305 306 307 |
# File 'lib/starter_web/_plugins/lunr_index.rb', line 301 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) ⇒ Object
296 297 298 299 |
# File 'lib/starter_web/_plugins/lunr_index.rb', line 296 def self.extract_title_and_url(item) data = item.to_liquid [ data['title'], data['url'] ] end |
Instance Method Details
#strip_index_suffix_from_url! ⇒ Object
315 316 317 |
# File 'lib/starter_web/_plugins/lunr_index.rb', line 315 def strip_index_suffix_from_url! @url.gsub!(/index\.html$/, '') end |
#strip_stopwords!(stopwords, min_length) ⇒ Object
remove anything that is in the stop words list from the text to be indexed
322 323 324 325 326 327 328 |
# File 'lib/starter_web/_plugins/lunr_index.rb', line 322 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 |