From 7df3ef0d1ed05f2584f283ead4e6b0b3c4093841 Mon Sep 17 00:00:00 2001 From: bayang Date: Mon, 26 Jun 2023 16:41:07 +0200 Subject: [PATCH] fix: search by tags (#171) --- src/site/_includes/components/searchScript.njk | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/site/_includes/components/searchScript.njk b/src/site/_includes/components/searchScript.njk index 69deb2c..903eb19 100644 --- a/src/site/_includes/components/searchScript.njk +++ b/src/site/_includes/components/searchScript.njk @@ -128,7 +128,7 @@ }) posts.forEach((p, idx) => { contentIndex.add({ - id: idx, title: p.title, content: p.content, //Change to removeHTML + id: idx, title: p.title, content: p.content, tags: p.tags //Change to removeHTML }) }); return contentIndex; @@ -333,7 +333,7 @@ function offlineSearch(searchQuery) { let data = window.docs; - let isTagSearch = search[0] === "#" && search.length > 1; + let isTagSearch = searchQuery[0] === "#" && searchQuery.length > 1; let searchResults = isTagSearch ? index.search(searchQuery.substring(1), [ @@ -361,7 +361,8 @@ } const allIds = new Set([ ...getByField("title"), - ...getByField("content") + ...getByField("content"), + ...getByField("tags") ]) const dataIds = [...allIds]; const finalResults = dataIds.map((id) => {