File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -31,11 +31,32 @@ <h1 class="thin">{{ .Title }}</h1>
31
31
const q = urlParams . get ( 'q' ) ;
32
32
if ( q ) {
33
33
setTimeout ( function ( ) {
34
- console . log ( 'Searching:' + q ) ;
35
34
pagefind . triggerSearch ( q ) ;
36
35
} , 1000 ) ;
37
36
}
37
+
38
+ $ ( "#search input" ) . on ( "input" , function ( ) {
39
+ var inputValue = $ ( this ) . val ( ) ;
40
+ var queryStringVar = "q" ;
41
+ updateQueryString ( queryStringVar , inputValue ) ;
42
+ } ) ;
38
43
} ) ;
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
+ }
39
60
</ script >
40
61
41
62
</ div >
You can’t perform that action at this time.
0 commit comments