From 22a9c0ddfcb38a15d4340f532faca7733349702b Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Mon, 25 Oct 2021 06:31:09 +0000
Subject: [PATCH] docs updates, add search to main page, fix redir bug

---
 layouts/partials/search.html |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/layouts/partials/search.html b/layouts/partials/search.html
index 7ee139d..78b7765 100644
--- a/layouts/partials/search.html
+++ b/layouts/partials/search.html
@@ -126,13 +126,17 @@
     </button>`
     }
 
+    const redir = (id, term) => {
+        window.location.href = {{.Site.BaseURL}} + `${id}#:~:text=${encodeURIComponent(term)}`
+    }
+
     const source = document.getElementById('search-bar')
     const results = document.getElementById("results-container")
     let term
     source.addEventListener("keyup", (e) => {
         if (e.key === "Enter") {
             const anchor = document.getElementsByClassName("result-card")[0]
-            window.location.href = `${anchor.id}#:~:text=${encodeURIComponent(term)}`
+            redir(anchor.id, term)
         }
     })
     source.addEventListener('input', (e) => {
@@ -163,9 +167,7 @@
                     .join("\n")
                 const anchors = document.getElementsByClassName("result-card");
                 [...anchors].forEach(anchor => {
-                    anchor.onclick = () => {
-                        window.location.href = `${anchor.id}#:~:text=${encodeURIComponent(term)}`
-                    }
+                    anchor.onclick = () => redir(anchor.id, term)
                 })
             }
         })

--
Gitblit v1.10.0