frontend: Normalize tags

This commit is contained in:
nemunaire 2025-03-29 12:14:41 +01:00
parent 42b9e54ec7
commit eaca60e5e0
3 changed files with 4 additions and 3 deletions

View file

@ -29,8 +29,8 @@
bind:value={filter}
>
<div>
{#each Object.keys($tags).sort(function (a, b) { return a.toLowerCase().localeCompare(b.toLowerCase()); }) as itag, index}
{#if (filter === "" && $tags[itag].count > 1) || (filter !== "" && itag.toLowerCase().indexOf(filter.toLowerCase()) >= 0)}
{#each Object.keys($tags).sort(function (a, b) { return a.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().localeCompare(b.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase()); }) as itag, index}
{#if (filter === "" && $tags[itag].count > 1) || (filter !== "" && itag.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().indexOf(filter.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase()) >= 0)}
<DropdownItem href="tags/{itag}">
#{itag}
<Badge>

View file

@ -59,6 +59,7 @@ export const tags = derived([my, themesStore], ([$my, $themesStore]) => {
for (const key in $themesStore) {
for (const exercice of $themesStore[key].exercices) {
exercice.tags.forEach((tag) => {
tag = tag.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
if (!tags[tag])
tags[tag] = {count: 1, solved: 0};
else

View file

@ -25,7 +25,7 @@
for (let k in $themes) {
const th = $themes[k];
for (const ex of th.exercices) {
if (ex.tags.indexOf(data.tag) >= 0) {
if (ex.tags.map(t => t.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase()).indexOf(data.tag.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase()) >= 0) {
tmp_exercices.push({theme: th, exercice: ex, index: k + "," + ex.id});
}
}