Skip to content

Commit

Permalink
normale strings for searching
Browse files Browse the repository at this point in the history
  • Loading branch information
elmuerte committed Mar 4, 2024
1 parent c06ec73 commit 9dd68d1
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,14 @@ <h1 class="no-anchor" data-toc-skip>
target.innerHTML += rendered;
}

function normalizeString(str) {
return str
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "")
.replace(/\s+/g, " ")
.toLowerCase();
}

function matchesQuote(quote, params) {
if (!quote) {
return false;
Expand All @@ -337,13 +345,17 @@ <h1 class="no-anchor" data-toc-skip>
} else if (params.game && params.game !== quote.game) {
return false;
}
if (
params.query &&
!quote.message
.toLowerCase()
.includes(params.query.toLowerCase())
) {
return false;
if (params.query) {
if (!quote.searchMessage) {
quote.searchMessage = normalizeString(quote.message);
}
if (
!quote.searchMessage.includes(
params.query.toLowerCase(),
)
) {
return false;
}
}
return true;
}
Expand All @@ -366,7 +378,9 @@ <h1 class="no-anchor" data-toc-skip>
if (event) {
event.preventDefault();
}
const query = document.getElementById("search").value;
const query = normalizeString(
document.getElementById("search").value,
);
if (!query) {
return;
}
Expand Down

0 comments on commit 9dd68d1

Please sign in to comment.