From 37f1541c206044e8af4546a97e17c6550cf8979a Mon Sep 17 00:00:00 2001 From: Jimmy Cai Date: Sun, 20 Oct 2024 00:26:59 +0200 Subject: [PATCH] feat: search box in 404 page (#1081) --- assets/ts/search.tsx | 9 ++++++++- layouts/404.html | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/assets/ts/search.tsx b/assets/ts/search.tsx index 856b48d..1c81dd1 100644 --- a/assets/ts/search.tsx +++ b/assets/ts/search.tsx @@ -53,7 +53,14 @@ class Search { this.resultTitle = resultTitle; this.resultTitleTemplate = resultTitleTemplate; - this.handleQueryString(); + /// Check if there's already value in the search input + if (this.input.value.trim() !== '') { + this.doSearch(this.input.value.split(' ')); + } + else { + this.handleQueryString(); + } + this.bindQueryStringChange(); this.bindSearchForm(); } diff --git a/layouts/404.html b/layouts/404.html index b89d2b6..98f4a67 100644 --- a/layouts/404.html +++ b/layouts/404.html @@ -3,5 +3,43 @@

{{ T "notFound.title" }}

{{ T "notFound.subtitle" }}

+ + {{- $query := first 1 (where .Site.Pages "Layout" "==" "search") -}} + {{- $searchPage := index $query 0 -}} + + {{- with $searchPage -}} +
+

+ + + + +

+
+ +
+

+
+
+ + + + {{- $opts := dict "minify" hugo.IsProduction "JSXFactory" "createElement" -}} + {{- $searchScript := resources.Get "ts/search.tsx" | js.Build $opts -}} + + + + {{- end -}} {{ partialCached "footer/footer" . }} {{ end }} \ No newline at end of file