fix issue with ancors, add comments
This commit is contained in:
parent
1fd7175e56
commit
edb36ed424
1 changed files with 16 additions and 3 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
/**
|
||||||
|
* Clean URLs from anchors
|
||||||
|
* @param {string} url Link URL
|
||||||
|
* @returns Link URL cleaned
|
||||||
|
*/
|
||||||
|
const cleanURL = (url) => url.split("#")[0];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the filetree
|
* Build the filetree
|
||||||
* @param {HTMLElement} parent Root element of the filetree
|
* @param {HTMLElement} parent Root element of the filetree
|
||||||
|
@ -30,7 +37,7 @@ const buildFileTree = (parent, data, location) => {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// File
|
// File
|
||||||
const url = 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 = item.name;
|
||||||
a.href = `${url}?q=${location}${item.name}`;
|
a.href = `${url}?q=${location}${item.name}`;
|
||||||
|
@ -66,7 +73,7 @@ const uncollapse = (element) => {
|
||||||
* Find the deepest opened directory
|
* Find the deepest opened directory
|
||||||
* @param {string[]} path Current path we are looking at, init with fullpath
|
* @param {string[]} path Current path we are looking at, init with fullpath
|
||||||
* @param {NodeListOf<ChildNode>} options Options we have, init with list root
|
* @param {NodeListOf<ChildNode>} options Options we have, init with list root
|
||||||
* @returns
|
* @returns The deepest node
|
||||||
*/
|
*/
|
||||||
const deepestNodeOpened = (path, options) => {
|
const deepestNodeOpened = (path, options) => {
|
||||||
if (path[0] === "") {
|
if (path[0] === "") {
|
||||||
|
@ -91,6 +98,12 @@ const deepestNodeOpened = (path, options) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search in the filetree, when nothing is aske, returns to initial state
|
||||||
|
* @param {string} query Query
|
||||||
|
* @param {HTMLElement} parent Filetree
|
||||||
|
* @param {HTMLLIElement} currentFile Current file opened
|
||||||
|
*/
|
||||||
const searchFiles = (query, parent, currentFile) => {
|
const searchFiles = (query, parent, currentFile) => {
|
||||||
// Prevent blocking the main thread
|
// Prevent blocking the main thread
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
|
@ -136,7 +149,7 @@ window.addEventListener("load", () => {
|
||||||
dataElement.remove();
|
dataElement.remove();
|
||||||
|
|
||||||
// Open nested openeded directories
|
// Open nested openeded directories
|
||||||
const infoURL = window.location.href.split("?");
|
const infoURL = cleanURL(window.location.href).split("?");
|
||||||
const fullpath = infoURL.length > 1 ? infoURL[1].substring(2) : "index.md";
|
const fullpath = infoURL.length > 1 ? infoURL[1].substring(2) : "index.md";
|
||||||
const path = fullpath.substring(0, fullpath.lastIndexOf("/"));
|
const path = fullpath.substring(0, fullpath.lastIndexOf("/"));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue