Basic cours support #44

Merged
Anri merged 67 commits from cours into main 2024-04-01 18:11:49 +02:00
Showing only changes of commit a9f48a79a4 - Show all commits

View file

@ -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();