remove shys from Search

This commit is contained in:
Alexander Bocken 2024-01-10 10:55:59 +01:00
parent c616c9d798
commit 95ae0f814c
Signed by: Alexander
GPG Key ID: 1D237BE83F9B05E8

View File

@ -2,7 +2,6 @@
import {onMount} from "svelte";
import "$lib/css/nordtheme.css";
onMount(() => {
const recipes = document.querySelectorAll(".search_me");
const search = document.getElementById("search");
@ -10,7 +9,7 @@ onMount(() => {
function do_search(click_only_result=false){
// grab search input value
const searchText = search.value.toLowerCase().trim().normalize('NFD').replace(/\p{Diacritic}/gu, "");
const searchText = search.value.toLowerCase().trim().normalize('NFD').replace(/\p{Diacritic}/gu, "");
const searchTerms = searchText.split(" ");
const hasFilter = searchText.length > 0;
@ -18,7 +17,7 @@ onMount(() => {
let scrollers = [];
// for each recipe hide all but matched
recipes.forEach(recipe => {
const searchString = `${recipe.textContent} ${recipe.dataset.tags}`.toLowerCase().normalize('NFD').replace(/\p{Diacritic}/gu, "");
const searchString = `${recipe.textContent} ${recipe.dataset.tags}`.toLowerCase().normalize('NFD').replace(/\p{Diacritic}/gu, "").replace(/­|­/g, '');
const isMatch = searchTerms.every(term => searchString.includes(term));
recipe.style.display = (isMatch ? 'flex' : 'none');