From ef40ea96d7fb6981189c75baa03d5f1652369fc2 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 13 Dec 2024 15:16:07 +0100 Subject: [PATCH] bugs in index (fix #90) --- static/js/cours.js | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/static/js/cours.js b/static/js/cours.js index 391a5a2..721b23f 100644 --- a/static/js/cours.js +++ b/static/js/cours.js @@ -137,29 +137,27 @@ window.addEventListener("load", () => { // Open nested openeded directories const infoURL = window.location.href.split("?"); - if (infoURL.length > 1) { - const fullpath = infoURL[1].substring(2); - const path = fullpath.substring(0, fullpath.lastIndexOf("/")); + const fullpath = infoURL.length > 1 ? infoURL[1].substring(2) : "index.md"; + const path = fullpath.substring(0, fullpath.lastIndexOf("/")); - const currentlyOpen = deepestNodeOpened( - path.split("/"), - fileTreeElement.querySelector("ul").childNodes - ); - uncollapse(currentlyOpen); + const currentlyOpen = deepestNodeOpened( + path.split("/"), + fileTreeElement.querySelector("ul").childNodes + ); + uncollapse(currentlyOpen); - // Bold opened file - const openedFile = decodeURI(fullpath.split("/").at(-1)); - currentlyOpen.querySelector("ul").childNodes.forEach((el) => { - if (el.innerText === openedFile) { - el.style.fontWeight = "bold"; - } - }); + // Bold opened file + const openedFile = decodeURI(fullpath.split("/").at(-1)); + currentlyOpen.querySelector("ul").childNodes.forEach((el) => { + if (el.innerText === openedFile) { + el.style.fontWeight = "bold"; + } + }); - // Search bar hook - document.getElementById("searchBar").addEventListener("input", (e) => { - searchFiles(e.target.value, fileTreeElement, currentlyOpen); - }); - } + // Search bar hook + document.getElementById("searchBar").addEventListener("input", (e) => { + searchFiles(e.target.value, fileTreeElement, currentlyOpen); + }); // Responsive menu let menuOpen = false;