From 461e961c0e14b56bc265d56a2471efb4be84ff2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E6=97=A5=E8=AF=AD?= Date: Thu, 18 Apr 2024 12:18:13 +0800 Subject: [PATCH] [feat] algolia_search filter (#434) --- source/js/search/algolia-search.js | 130 +++++++++++++++-------------- 1 file changed, 68 insertions(+), 62 deletions(-) diff --git a/source/js/search/algolia-search.js b/source/js/search/algolia-search.js index 573a96082..2398bf014 100644 --- a/source/js/search/algolia-search.js +++ b/source/js/search/algolia-search.js @@ -1,69 +1,75 @@ utils.jq(() => { - var $inputArea = $("input#search-input"); - if ($inputArea.length === 0) { + var $inputArea = $("input#search-input"); + if ($inputArea.length === 0) { + return; + } + + var $resultArea = $("#search-result"); + var $searchWrapper = $("#search-wrapper"); + var client = algoliasearch(window.searchConfig.appId, window.searchConfig.apiKey); + var index = client.initIndex(window.searchConfig.indexName); + + function filterResults(hits, filterPath) { + if (!filterPath || filterPath === '/') return hits; + var regex = new RegExp(filterPath); + return hits.filter(hit => regex.test(hit.url)); + } + + function displayResults(hits) { + var $resultList = $("