diff --git a/static/js/cours.js b/static/js/cours.js index c8ea5f3..a28b4dd 100644 --- a/static/js/cours.js +++ b/static/js/cours.js @@ -2,8 +2,9 @@ * Build the filetree * @param {HTMLElement} parent Root element of the filetree * @param {{name: string, is_dir: boolean, children: any[]}} data FileNode + * @param {string} location Current location, used for links creation */ -const buildFileTree = (parent, data) => { +const buildFileTree = (parent, data, location) => { const ul = document.createElement("ul"); data.forEach((item) => { const li = document.createElement("li"); @@ -22,7 +23,11 @@ const buildFileTree = (parent, data) => { ul.appendChild(li); if (item.children && item.children.length > 0) { - buildFileTree(li, item.children); + buildFileTree( + li, + item.children, + item.is_dir ? location + `${item.name}/` : location + ); } }); @@ -35,7 +40,8 @@ window.addEventListener("load", () => { buildFileTree( fileTreeElement, - JSON.parse(dataElement.getAttribute("data-json")).children + JSON.parse(dataElement.getAttribute("data-json")).children, + "" ); dataElement.remove();