Allow searching via ?q=
This commit is contained in:
parent
8c01130950
commit
522d174dba
|
@ -24,9 +24,9 @@ type: website
|
|||
Hey! I'm <a href='https://ricostacruz.com'>@rstacruz</a> and this is a
|
||||
modest collection of cheatsheets I've written.
|
||||
</p>
|
||||
<form data-js-search-form class='search'>
|
||||
<form data-js-search-form class='search' action='.' method='get'>
|
||||
<label class='search-box'>
|
||||
<input type='text' placeholder='Search...' autofocus data-js-search-input>
|
||||
<input name='q' type='text' placeholder='Search...' autofocus data-js-search-input>
|
||||
</label>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -64,6 +64,12 @@ $(function () {
|
|||
Search.show(val)
|
||||
}
|
||||
})
|
||||
|
||||
const query = (qs(window.location.search) || {}).q
|
||||
if (query && query.length) {
|
||||
$this.val(query)
|
||||
Search.show(query)
|
||||
}
|
||||
})
|
||||
|
||||
$('[data-js-search-form]').each(function () {
|
||||
|
@ -207,3 +213,21 @@ function groupify ($this, { tag, wrapper, body }) {
|
|||
return $wrap
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper: minimal qs implementation
|
||||
*/
|
||||
|
||||
function qs (search) {
|
||||
search = search.substr(1)
|
||||
const parts = search.split('&').map(p => p.split('='))
|
||||
return parts.reduce((result, part) => {
|
||||
result[part[0]] = qsdecode(part[1])
|
||||
return result
|
||||
}, {})
|
||||
}
|
||||
|
||||
function qsdecode (string) {
|
||||
string = string.replace(/\+/g, ' ')
|
||||
return string
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue