From 99507a29530501c6074975360f817f332bb5d777 Mon Sep 17 00:00:00 2001
From: annegf <anne.garciafernandez@univ-grenoble-alpes.fr>
Date: Tue, 4 Feb 2025 17:32:36 +0100
Subject: [PATCH] Group by book, add HTML title for books and move chapter info

---
 static/js/auto_app_minisearch.js | 39 ++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 14 deletions(-)

diff --git a/static/js/auto_app_minisearch.js b/static/js/auto_app_minisearch.js
index f9077401..f0a9c374 100644
--- a/static/js/auto_app_minisearch.js
+++ b/static/js/auto_app_minisearch.js
@@ -14,22 +14,30 @@ const renderSearchResults = (results) => {
     //JSON.stringify(results);
     //results = results.filter((result) => result.book == 1)//filter book 1
     //results.sort((a,b) => a.n - b.n); //sort by n (only)
-    // sort by book, and then n (line number)
-    results.sort((a,b) => {
-      if (a.book < b.book) return -1;
-      if (a.book > b.book) return 1;
-      if (a.n < b.n) return -1;
-      if (a.n > b.n) return 1;
-      return 0;
+    
+    const books = new Set(results.map(a => a.book));
+    
+    let $result;
+    $resultsList.innerHTML = "";
+    for (let b of books){
+        $resultsList.innerHTML += "<h4>Livre "+b+"</h4>\n";
+        //filter by book
+        results_by_book = results.filter((result) => result.book == b)
+        //sort by n
+        results_by_book.sort((a,b) => {
+        return (a.n - b.n);
     });
-    $resultsList.innerHTML = results.map(({ book, chapter, n, lem,BnFfr4967, BnFfr5299, BnFfr23145, BnFfr49967, Cha514, BnFfr23146, BnFfr17274, Vat966,
+    
+    //}
+    
+    $resultsList.innerHTML += results_by_book.map(({ book, chapter, n, lem,BnFfr4967, BnFfr5299, BnFfr23145, BnFfr49967, Cha514, BnFfr23146, BnFfr17274, Vat966,
 Aix419, BnFfr1724, Aix966 }) => {
-    let $result=`<h5 xmlns="http://www.w3.org/1999/xhtml" class="mt-3">Vers <a href="/book${book}/${chapter}#${n}">${n}</a></h5><dl xmlns="http://www.w3.org/1999/xhtml">
-   <dt>Livre : </dt>
-   <dd>${book}</dd>
-   <dt>Chapitre : </dt>
-   <dd>${chapter}</dd>
-   <dt>Lemme :</dt>
+    let $chap = `${chapter}`.substring(0, `${chapter}`.indexOf("_"));
+    $result='<h5 xmlns="http://www.w3.org/1999/xhtml" class="mt-3">Vers <a href="';
+    $result+=`/book${book}/${chapter}#${n}">${n}</a> (chapitre `
+    $result+=$chap
+    $result+=`)</h5><dl xmlns="http://www.w3.org/1999/xhtml">
+    <dt>Lemme :</dt>
    <dd>${lem}</dd>`
     if (! (`${BnFfr4967}` === "undefined") ) {
       $result += `
@@ -87,8 +95,11 @@ Aix419, BnFfr1724, Aix966 }) => {
    <dd>${Aix966}</dd>
     `}
     $result += `</dl>`
+    
     return $result
 }).join('\n')
+}
+
 
         if (results.length > 0) {
             $app.classList.add('hasResults')
-- 
GitLab