File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,14 @@ class Search {
53
53
this . resultTitle = resultTitle ;
54
54
this . resultTitleTemplate = resultTitleTemplate ;
55
55
56
- this . handleQueryString ( ) ;
56
+ /// Check if there's already value in the search input
57
+ if ( this . input . value . trim ( ) !== '' ) {
58
+ this . doSearch ( this . input . value . split ( ' ' ) ) ;
59
+ }
60
+ else {
61
+ this . handleQueryString ( ) ;
62
+ }
63
+
57
64
this . bindQueryStringChange ( ) ;
58
65
this . bindSearchForm ( ) ;
59
66
}
Original file line number Diff line number Diff line change 3
3
< h1 class ="article-title "> {{ T "notFound.title" }}</ h1 >
4
4
< h2 class ="article-subtitle "> {{ T "notFound.subtitle" }}</ h2 >
5
5
</ div >
6
+
7
+ {{- $query := first 1 (where .Site.Pages "Layout" "==" "search") -}}
8
+ {{- $searchPage := index $query 0 -}}
9
+
10
+ {{- with $searchPage -}}
11
+ < form action ="{{ $searchPage.RelPermalink }} " class ="search-form widget " {{ with .OutputFormats.Get "json" -}}data-json="{{ .Permalink }} " {{- end }} >
12
+ < p >
13
+ < label > {{ T "search.title" }}</ label >
14
+ < input id ="searchInput " name ="keyword " required placeholder ="{{ T `search.placeholder` }} " />
15
+
16
+ < button title ="{{ T `search.title` }} ">
17
+ {{ partial "helper/icon" "search" }}
18
+ </ button >
19
+ </ p >
20
+ </ form >
21
+
22
+ < div class ="search-result ">
23
+ < h3 class ="search-result--title section-title "> </ h3 >
24
+ < div class ="search-result--list article-list--compact "> </ div >
25
+ </ div >
26
+
27
+ < script >
28
+ window . searchResultTitleTemplate = "{{ T `search.resultTitle` }}"
29
+ </ script >
30
+
31
+ {{- $opts := dict "minify" hugo.IsProduction "JSXFactory" "createElement" -}}
32
+ {{- $searchScript := resources.Get "ts/search.tsx" | js.Build $opts -}}
33
+ < script type ="text/javascript " src ="{{ $searchScript.RelPermalink }} " defer > </ script >
34
+
35
+ < script >
36
+ const wrongUrl = new URL ( window . location . href ) ;
37
+
38
+ /// Get the search keyword from the wrong URL by removing all slashes and dashes
39
+ const searchKeyword = wrongUrl . pathname . split ( / [ / | - ] / ) . join ( ' ' ) . trim ( ) ;
40
+
41
+ document . getElementById ( 'searchInput' ) . setAttribute ( 'value' , searchKeyword ) ;
42
+ </ script >
43
+ {{- end -}}
6
44
{{ partialCached "footer/footer" . }}
7
45
{{ end }}
You can’t perform that action at this time.
0 commit comments