Closed mukkoo closed 7 years ago
Hi @mukkoo, thanks for the report!
It seems odd that Middleman skips partials when rendering without a layout. Though it seems to be the case when rendering in middleman-search, if I set a layout for a specific page to false
in its frontmatter, then middleman displays it without layout but including partials (at least in version 3, I haven't tried 4).
Considering that, before going the Nokogiri way, I'd try to invest more time in figuring out what is causing middleman to skip partials in search-index-resource
. If you want to tackle that, great; if not, I'll work on that some time during next week.
@matiasgarciaisaia what do you think?
I don't really like the proposed alternative - seems too hacky for me :/
I'll second @spalladino - if middleman is behaving weird with partials, let's find out why. Rendering all the HTML just to get some part of it - it doesn't seem sensible.
Thanks for the catch, @mukkoo! Hope to give you good news soon :)
Hi, @mukkoo - sorry for the delay.
We took some time with @spalladino to test this (you can check our test project), and - we couldn't repro the issue :(
We created a partial with a pretty much unique word, and middleman-search correctly indexed it.
I don't think it had to do with any of the changes we did in the gem, but check it - we may have fixed it, or who knows what's going on.
If you have any more info to share, we'll take another look later - during the next 2~7 months, perhaps 😛
Closing after 1 month
Hi,
using this gem I had a problem: the partials are not indexed.
Reading the code I've found (perhaps) the source of problem. In
search-index-resource.rb:112
callingrender()
method with{:layout => false}
the result doesn't contains any partials.I haven't found any other
resource
method to have clean content with, already, partials.The solution that I've found is Nokogiri side and not Middleman side.
I'll try to describe it:
search-index-resource.rb
fromhtml = resource.render( { :layout => false }, { :current_path => resource.path } )
tohtml = resource.render({ :current_path => resource.path } )
search-index-resource.rb
fromNokogiri::HTML(html).xpath("//text()").text
toNokogiri::HTML(html).xpath("//body/*[not(@class='some_class') and not(@class='another_class')]//text()").to_a.join(" ")
some_class
andanother_class
can be passed with an array from configurations. Something like this:What do you think about this solution?
If right I can work to a PR.