Skip to content

Commit a2de621

Browse files
committed
Updates querystring to match what is being searched so we have a permalink of the search
Signed-off-by: Chris Abraham <[email protected]>
1 parent 0855a26 commit a2de621

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

layouts/_default/search.html

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,32 @@ <h1 class="thin">{{ .Title }}</h1>
3131
const q = urlParams.get('q');
3232
if(q){
3333
setTimeout(function(){
34-
console.log('Searching:'+q);
3534
pagefind.triggerSearch(q);
3635
}, 1000);
3736
}
37+
38+
$("#search input").on("input", function() {
39+
var inputValue = $(this).val();
40+
var queryStringVar = "q";
41+
updateQueryString(queryStringVar, inputValue);
42+
});
3843
});
44+
45+
function updateQueryString(key, value) {
46+
var baseUrl = window.location.href.split("?")[0];
47+
var queryString = window.location.search.slice(1);
48+
var urlParams = new URLSearchParams(queryString);
49+
50+
if (urlParams.has(key)) {
51+
urlParams.set(key, value);
52+
} else {
53+
urlParams.append(key, value);
54+
}
55+
56+
var newUrl = baseUrl + "?" + urlParams.toString();
57+
// Update the browser history (optional)
58+
window.history.pushState({}, null, newUrl);
59+
}
3960
</script>
4061

4162
</div>

0 commit comments

Comments
 (0)