hide .md extension from filetree, also capitalize entries
This commit is contained in:
parent
d4143f7ef1
commit
afb0ad038f
1 changed files with 12 additions and 2 deletions
|
@ -5,10 +5,18 @@
|
||||||
*/
|
*/
|
||||||
const cleanURL = (url) => url.split("#")[0];
|
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
|
* Build the filetree
|
||||||
* @param {HTMLElement} parent Root element of 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
|
* @param {string} location Current location, used for links creation
|
||||||
*/
|
*/
|
||||||
const buildFileTree = (parent, data, location) => {
|
const buildFileTree = (parent, data, location) => {
|
||||||
|
@ -39,7 +47,9 @@ const buildFileTree = (parent, data, location) => {
|
||||||
// File
|
// File
|
||||||
const url = cleanURL(window.location.href).split("?")[0];
|
const url = cleanURL(window.location.href).split("?")[0];
|
||||||
const a = document.createElement("a");
|
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}`;
|
a.href = `${url}?q=${location}${item.name}`;
|
||||||
li.appendChild(a);
|
li.appendChild(a);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue