From a83d026bc439b7d7d712f9d573228b78a282600b Mon Sep 17 00:00:00 2001 From: Orka Arnest CRUZE Date: Thu, 18 Jul 2024 19:20:57 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20tags=20dans=20cards=20des=20r=C3=A9sult?= =?UTF-8?q?ats=20de=20recherche=20#28?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _includes/components/pagefind_filters.njk | 4 ++-- content/fr/blog/posts/accordeon.md | 12 ---------- public/js/search-results.js | 29 ++++++++++++++++++----- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/_includes/components/pagefind_filters.njk b/_includes/components/pagefind_filters.njk index 4db3610..e04b644 100644 --- a/_includes/components/pagefind_filters.njk +++ b/_includes/components/pagefind_filters.njk @@ -4,8 +4,8 @@ {% if espace %} {% for item in espace %}{{ item }}{% endfor %} {% endif %} -{% if profile %} - {% for item in profile %}{{ item }}{% endfor %} +{% if profil %} + {% for item in profil %}{{ item }}{% endfor %} {% endif %} {% if tags %} {% for item in tags %}{{ item }}{% endfor %} diff --git a/content/fr/blog/posts/accordeon.md b/content/fr/blog/posts/accordeon.md index 397a405..d7c69db 100644 --- a/content/fr/blog/posts/accordeon.md +++ b/content/fr/blog/posts/accordeon.md @@ -5,18 +5,6 @@ date: git Last Modified tags: - DSFR - composant -format: - - Initiation - - Tutoriel - - Référentiel technique - - Article -profile: - - Utilisateur - - Producteur - - Développeur -espace: - - Ecosystème Géoplateforme - - Organismes producteurs --- Chaque composant peut être inclus dans un fichier Nunjucks `.njk` ou Markdown `.md`. diff --git a/public/js/search-results.js b/public/js/search-results.js index 99415b4..2da8459 100644 --- a/public/js/search-results.js +++ b/public/js/search-results.js @@ -75,7 +75,7 @@ class PageFinder { paginatedResults.forEach((result) => { const cardCol = document.createElement("div"); cardCol.className = FULL_WIDTH_COL_CLASS; - cardCol.innerHTML = this._getCardHtml(result.meta.title, result.excerpt, result.url); + cardCol.innerHTML = this._getCardHtml(result.meta.title, result.excerpt, result.url, Object.values(result.filters).flat()); this.searchResultList.appendChild(cardCol); }); } @@ -90,7 +90,7 @@ class PageFinder { Object.entries(filters).map(([filterType, subFilter]) => { let div = document.createElement("div"); - div.className = "fr-grid-row fr-grid-row--middle fr-mb-2v"; + div.className = "fr-grid-row fr-grid-row--middle fr-my-2v"; let divTitle = document.createElement("div"); divTitle.className = "fr-col-12 fr-col-sm-2"; @@ -99,12 +99,16 @@ class PageFinder { let divTags = document.createElement("div"); divTags.className = "fr-col-12 fr-col-sm-10"; + let ulTags = document.createElement("ul"); + ulTags.className = "fr-tags-group"; + divTags.appendChild(ulTags); + div.appendChild(divTitle); div.appendChild(divTags); Object.entries(subFilter).map(([filterKeyword, count]) => { const button = document.createElement("button"); - button.className = "fr-tag fr-mx-2v"; + button.className = "fr-tag"; button.ariaPressed = initHashFilters[filterType]?.includes(filterKeyword) ? "true" : "false"; button.textContent = `${filterKeyword} (${count})`; @@ -117,7 +121,7 @@ class PageFinder { if (button.ariaPressed === "true") { // on enlève hashFilters[filterType] = hashFilters[filterType]?.filter((f) => f !== filterKeyword); - if (hashFilters[filterType].length === 0) { + if (hashFilters[filterType]?.length === 0) { delete hashFilters[filterType]; } } else { @@ -128,7 +132,7 @@ class PageFinder { window.location.hash = Object.keys(hashFilters).length === 0 ? "" : encodeURIComponent(JSON.stringify(hashFilters)); }); - divTags.appendChild(button); + ulTags.appendChild(button); }); this.filterTagsEl.appendChild(div); @@ -179,7 +183,7 @@ class PageFinder { return filters; } - _getCardHtml(title, excerpt, url) { + _getCardHtml(title, excerpt, url, filters = []) { return ` `;