Class: Jekyll::LunrJsSearch::SearchEntry
- Inherits:
-
Object
- Object
- Jekyll::LunrJsSearch::SearchEntry
- Defined in:
- lib/jekyll_lunr_js_search/search_entry.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
- .create(page_or_post, renderer) ⇒ Object
- .create_from_page(page, renderer) ⇒ Object
- .create_from_post(post, renderer) ⇒ Object
- .extract_title_and_url(item) ⇒ Object
Instance Method Summary collapse
-
#initialize(title, url, date, categories, body) ⇒ 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, url, date, categories, body) ⇒ SearchEntry
Returns a new instance of SearchEntry.
37 38 39 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 37 def initialize(title, url, date, categories, body) @title, @url, @date, @categories, @body = title, url, date, categories, body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
35 36 37 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 35 def body @body end |
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
35 36 37 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 35 def categories @categories end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
35 36 37 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 35 def date @date end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
35 36 37 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 35 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
35 36 37 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 35 def url @url end |
Class Method Details
.create(page_or_post, renderer) ⇒ Object
6 7 8 9 10 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 6 def self.create(page_or_post, renderer) return create_from_post(page_or_post, renderer) if page_or_post.is_a?(Jekyll::Post) return create_from_page(page_or_post, renderer) if page_or_post.is_a?(Jekyll::Page) raise 'Not supported' end |
.create_from_page(page, renderer) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 12 def self.create_from_page(page, renderer) title, url = extract_title_and_url(page) body = renderer.render(page) date = nil categories = [] SearchEntry.new(title, url, date, categories, body) end |
.create_from_post(post, renderer) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 21 def self.create_from_post(post, renderer) title, url = extract_title_and_url(post) body = renderer.render(post) date = post.date categories = post.categories SearchEntry.new(title, url, date, categories, body) end |
.extract_title_and_url(item) ⇒ Object
30 31 32 33 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 30 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
41 42 43 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 41 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
46 47 48 49 50 51 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 46 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 |