From 00900562f8f8c4db0c306653b923061f9dffb0f3 Mon Sep 17 00:00:00 2001
From: weru <onewesh@gmail.com>
Date: Thu, 12 Nov 2020 01:21:34 +0000
Subject: [PATCH] update

---
 assets/js/search.js    |   26 +++++++++++++++++---------
 assets/js/functions.js |    4 ----
 2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/assets/js/functions.js b/assets/js/functions.js
index d1f9180..5ce18d2 100644
--- a/assets/js/functions.js
+++ b/assets/js/functions.js
@@ -110,10 +110,6 @@
 function wrapText(text, context, wrapper = 'div') {
   let c = context.innerHTML;
   let index = c.indexOf(text);
-  if(index >= 0) {
-    const cc = `${c.charAt(0)}${c.substring(1,c.length)}`;
-    index = cc.indexOf(Text);
-  }
   if (index >= 0) {
     let stop = index + text.length;
     let s = c.substring(index,stop);
diff --git a/assets/js/search.js b/assets/js/search.js
index a32e9f7..e800f3b 100644
--- a/assets/js/search.js
+++ b/assets/js/search.js
@@ -11,8 +11,6 @@
 const searchKeys = ['title', 'link', 'body', 'id'];
 const searchOptions = {
   ignoreLocation: true,
-  includeScore: true,
-  includeMatches: true,
   keys: searchKeys,
   threshold: 0.1
 };
@@ -49,12 +47,17 @@
 
   if (searchField) {
     searchField.addEventListener('input', function() {
-      const searchTerm = this.value.trim().replaceAll(" ", " +").toLowerCase();
+      const searchTerm = this.value.trim().toLowerCase();
       if(searchTerm.length >= 3) {
         let rawResults = index.search(searchTerm);
         rawResults = rawResults.map(function(result){
-          return result.item;
+          const matches = result.matches;
+          const resultItem = result.item;
+          resultItem.matches = matches;
+          return resultItem;
         });
+        console.log(JSON.stringify(rawResults));
+        console.log(rawResults);
 
         if(rawResults.length) {
 
@@ -89,11 +92,14 @@
 function findQuery(query = 'query') {
   const urlParams = new URLSearchParams(window.location.search);
   if(urlParams.has(query)){
-    const searchTerm = urlParams.get(query);
-    window.find(searchTerm);
-    return searchTerm;
+    let c = urlParams.get(query);
+    window.find(c);
+    cc = `${c.charAt(0).toUpperCase()}${c.substring(1,c.length)}`;
+    window.find(cc);
+    console.log(c.length);
+    return [c, cc];
   }
-  return "";
+  return ["",""];
 }
 
 let main = elem('main');
@@ -101,6 +107,8 @@
   main = elem('.main');
 }
 const searchQuery = findQuery();
-wrapText(searchQuery,main,'mark');
+console.log(searchQuery);
+wrapText(searchQuery[0],main,'mark');
+wrapText(searchQuery[1],main,'mark');
 
 window.addEventListener('load', () => search());
\ No newline at end of file

--
Gitblit v1.10.0