Class: Jekyll::LunrJsSearch::PageRenderer
- Inherits:
-
Object
- Object
- Jekyll::LunrJsSearch::PageRenderer
- Defined in:
- lib/jekyll_lunr_js_search/page_renderer.rb
Instance Method Summary collapse
-
#initialize(site) ⇒ PageRenderer
constructor
A new instance of PageRenderer.
-
#render(item) ⇒ Object
render the item, parse the output and get all text inside <p> elements.
Constructor Details
#initialize(site) ⇒ PageRenderer
Returns a new instance of PageRenderer.
6 7 8 |
# File 'lib/jekyll_lunr_js_search/page_renderer.rb', line 6 def initialize(site) @site = site end |
Instance Method Details
#render(item) ⇒ Object
render the item, parse the output and get all text inside <p> elements
11 12 13 14 15 16 |
# File 'lib/jekyll_lunr_js_search/page_renderer.rb', line 11 def render(item) item.render({}, @site.site_payload) doc = Nokogiri::HTML(item.output) paragraphs = doc.search('//text()').map {|t| t.content } paragraphs = paragraphs.join(" ").gsub("\r", " ").gsub("\n", " ").gsub("\t", " ").gsub(/\s+/, " ") end |