remove accents from search input and search string (#810)

This commit is contained in:
James Wilcock 2022-07-02 13:08:17 -07:00 committed by GitHub
parent 44745037c4
commit ab89221a8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -28,7 +28,7 @@ document.addEventListener("DOMContentLoaded", () => {
search.addEventListener("input", () => {
// grab search input value
const searchText = search.value.toLowerCase().trim();
const searchText = search.value.toLowerCase().trim().normalize('NFD').replace(/\p{Diacritic}/gu, "");
const searchTerms = searchText.split(" ");
const hasFilter = searchText.length > 0;
@ -37,7 +37,7 @@ document.addEventListener("DOMContentLoaded", () => {
// for each recipe hide all but matched
recipes.forEach(recipe => {
const searchString = `${recipe.textContent} ${recipe.dataset.tags}`.toLowerCase();
const searchString = `${recipe.textContent} ${recipe.dataset.tags}`.toLowerCase().normalize('NFD').replace(/\p{Diacritic}/gu, "");
const isMatch = searchTerms.every(term => searchString.includes(term));
recipe.hidden = !isMatch;