mirror of
				https://github.com/Wonderfall/hugo-WonderMod.git
				synced 2025-10-31 03:45:24 +01:00 
			
		
		
		
	Fix results being searched before index building;
refactor resultSet generation to fix duplicate items with large db
This commit is contained in:
		| @@ -38,11 +38,6 @@ window.onload = function () { | |||||||
|     xhr.send(); |     xhr.send(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| function itemGen(name, link) { |  | ||||||
|     return `<li class="post-entry"><header class="entry-header">${name} »</header><a href="${link}" aria-label="${name}"></a></li>` |  | ||||||
| } |  | ||||||
|  |  | ||||||
| function activeToggle() { | function activeToggle() { | ||||||
|     document.activeElement.parentElement.classList.toggle("focus") |     document.activeElement.parentElement.classList.toggle("focus") | ||||||
| } | } | ||||||
| @@ -57,14 +52,15 @@ function reset() { | |||||||
| sInput.onkeyup = function (e) { | sInput.onkeyup = function (e) { | ||||||
|     // run a search query (for "term") every time a letter is typed |     // run a search query (for "term") every time a letter is typed | ||||||
|     // in the search box |     // in the search box | ||||||
|  |     if (fuse) { | ||||||
|         const results = fuse.search(this.value.trim()); // the actual query being run using fuse.js |         const results = fuse.search(this.value.trim()); // the actual query being run using fuse.js | ||||||
|  |  | ||||||
|         if (results.length !== 0) { |         if (results.length !== 0) { | ||||||
|             // build our html if result exists |             // build our html if result exists | ||||||
|             let resultSet = ''; // our results bucket |             let resultSet = ''; // our results bucket | ||||||
|  |  | ||||||
|             for (let item in results) { |             for (let item in results) { | ||||||
|             resultSet = resultSet + itemGen(results[item].item.title, results[item].item.permalink) |                 resultSet += `<li class="post-entry"><header class="entry-header">${results[item].item.title} »</header>` + | ||||||
|  |                     `<a href="${results[item].item.permalink}" aria-label="${results[item].item.title}"></a></li>` | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             resList.innerHTML = resultSet; |             resList.innerHTML = resultSet; | ||||||
| @@ -76,6 +72,7 @@ sInput.onkeyup = function (e) { | |||||||
|             resList.innerHTML = ''; |             resList.innerHTML = ''; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| sInput.addEventListener('search', function (e) { | sInput.addEventListener('search', function (e) { | ||||||
|     // clicked on x |     // clicked on x | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Aditya Telange
					Aditya Telange