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 of it.
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 of it
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/jekyll_lunr_js_search/page_renderer.rb', line 11 def render(item) if item.is_a?(Jekyll::Document) item.output = Jekyll::Renderer.new(@site, item).run else item.render({}, @site.site_payload) end doc = Nokogiri::HTML(item.output) paragraphs = doc.search('//div[contains(concat(" ", normalize-space(@class), " "), " article-body ")]').map {|t| t.content } paragraphs = paragraphs.join(" ").gsub("\r", " ").gsub("\n", " ").gsub("\t", " ").gsub(/\s+/, " ") paragraphs.strip end |