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); }