From afb0ad038fc03813bca64a8a42183874767162c4 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 14 Dec 2024 10:59:56 +0100 Subject: [PATCH] hide .md extension from filetree, also capitalize entries --- static/js/cours.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/static/js/cours.js b/static/js/cours.js index 5f539a9..5eb8869 100644 --- a/static/js/cours.js +++ b/static/js/cours.js @@ -5,10 +5,18 @@ */ const cleanURL = (url) => url.split("#")[0]; +/** + * Capitalize a text + * @param {string} text Input text + * @returns Capitalize text + */ +const capitalize = (text) => + text.length === 0 ? text : text[0].toUpperCase() + text.substring(1); + /** * Build the filetree * @param {HTMLElement} parent Root element of the filetree - * @param {{name: string, is_dir: boolean, children: any[]}} data FileNode + * @param {{name: string, is_dir: boolean, children: any[]}[]} data FileNode * @param {string} location Current location, used for links creation */ const buildFileTree = (parent, data, location) => { @@ -39,7 +47,9 @@ const buildFileTree = (parent, data, location) => { // File const url = cleanURL(window.location.href).split("?")[0]; const a = document.createElement("a"); - a.text = item.name; + a.text = capitalize( + item.name.endsWith(".md") ? item.name.slice(0, -3) : item.name + ); a.href = `${url}?q=${location}${item.name}`; li.appendChild(a); }