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.
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#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_document(document, 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.
45 46 47 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 45 def initialize(title, url, date, categories, body) @title, @url, @date, @categories, @body, @collection = title, url, date, categories, body, collection end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
43 44 45 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 43 def body @body end |
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
43 44 45 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 43 def categories @categories end |
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
43 44 45 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 43 def collection @collection end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
43 44 45 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 43 def date @date end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
43 44 45 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 43 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
43 44 45 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 43 def url @url end |
Class Method Details
.create(page_or_post, renderer) ⇒ Object
6 7 8 9 10 11 |
# 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) return create_from_document(page_or_post, renderer) if page_or_post.is_a?(Jekyll::Document) raise 'Item type not supported' end |
.create_from_document(document, renderer) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 13 def self.create_from_document(document, renderer) return if document.data["exclude_from_search"] || document.data["redirect_to"] body = renderer.render(document) data = document.to_liquid SearchEntry.new(data['title'], data['url'], Time.now, data['category'], body) end |
.create_from_page(page, renderer) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 20 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, nil) end |
.create_from_post(post, renderer) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 29 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, nil) end |
.extract_title_and_url(item) ⇒ Object
38 39 40 41 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 38 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
49 50 51 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 49 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
54 55 56 57 58 59 |
# File 'lib/jekyll_lunr_js_search/search_entry.rb', line 54 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 |