manastech / middleman-search

LunrJS-based search for Middleman
MIT License
58 stars 31 forks source link

Support relative links with search_index_path #5

Open rtack opened 8 years ago

rtack commented 8 years ago

Using search_index_path I always got the absolute path back but for hosting on github a relative path is needed.

I wrote my own helper which uses link_to to get the relative path.

def link_to_search_index
  absolute_link_to_index = '/' + extensions[:search].options[:index_path]
  dom = Nokogiri.HTML(link_to '', absolute_link_to_index)
  node = dom.at_xpath '//a'
  node[:href]
end
matiasgarciaisaia commented 8 years ago

Yeah - this is definitely an issue.

The real problem is, I think, that you can have the search box at different path levels (ie, at our site you can search from http://manas.com.ar/, http://manas.com.ar/staff, or http://manas.com.ar/staff/mgarcia). In those cases, if you want to use a relative URL you have to use them differently - or add any way to the page for declaring how many nesting levels to go back.

It's definitely doable, but I'm not that sure your helper works for all the cases. I'll give it a try - and start implementing that if works at least for a nice percentage of the cases. But I think there's more than that for this issue.

Thanks for the feedback! :)

matiasgarciaisaia commented 8 years ago

@rtack we've just released middleman-search v0.8.0, which includes #9

That should solve your issue. It doesn't use relative paths, but the absolute paths it uses honor the :http_prefix Middleman setting.

Can you confirm us this works?