Fix keyword search in Firefox and URL search via query param

Fixes #577.
This commit is contained in:
Thibaut Courouble 2017-02-19 09:34:59 -05:00
parent 476c69e419
commit ad044f85d3
3 changed files with 8 additions and 1 deletions

View file

@ -229,6 +229,7 @@ class App < Sinatra::Application
end
get '/' do
return redirect "/#q=#{params[:q]}" if params[:q]
return redirect '/' unless request.query_string.empty? # courtesy of HTML5 App Cache
response.headers['Content-Security-Policy'] = settings.csp if settings.csp
erb :index

View file

@ -17,6 +17,12 @@ class AppTest < MiniTest::Spec
assert last_response.ok?
end
it "redirects to /#q= when there is a 'q' query param" do
get '/search', q: 'foo'
assert last_response.redirect?
assert_equal 'http://example.org/#q=foo', last_response['Location']
end
it "redirects without the query string" do
get '/', foo: 'bar'
assert last_response.redirect?

View file

@ -5,7 +5,7 @@
<button type="button" class="_mobile-btn _menu-btn">Menu</button>
<button type="button" class="_mobile-btn _home-btn">Home</button>
<form class="_search" role="search">
<input type="search" class="_search-input" placeholder="Search&hellip;" autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false" maxlength="30" aria-label="Search">
<input type="search" name="q" class="_search-input" placeholder="Search&hellip;" autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false" maxlength="30" aria-label="Search">
<button type="reset" class="_search-clear" title="Clear search">Clear search</button>
<div class="_search-tag"></div>
</form>