diff --git a/src/lib/components/Navbar.svelte b/src/lib/components/Navbar.svelte index 6fdbca0..36ea4b3 100644 --- a/src/lib/components/Navbar.svelte +++ b/src/lib/components/Navbar.svelte @@ -3,7 +3,6 @@ let data = import.meta.glob("/src/routes/**/+page.md"); let paths = data; - export let items; /** * @param {Record Promise>} paths @@ -38,52 +37,37 @@ } const nestedFolders = buildHierarchy(paths); - console.log(nestedFolders) - // Helper function to recursively render the nested list - /** - * @param {{ [x: string]: any; }} node - */ - // function renderNestedList(node, prefix = "") { - // return Object.keys(node) - // .map((key) => { - // const fullPath = `${prefix}/${key}`; - // return `
  • ${key}
      ${renderNestedList( - // node[key], - // fullPath - // )}
  • `; - // }) - // .join(""); - // } + function createHtmlList(obj, parentPath = "", depth = 0) { + let html = ""; - function createHtmlList(obj, parentPath = '') { - let html = ''; + for (const key in obj) { + const currentPath = parentPath ? `${parentPath}/${key}` : key; - for (const key in obj) { - const currentPath = parentPath ? `${parentPath}/${key}` : key; - - if (typeof obj[key] === 'object' && Object.keys(obj[key]).length > 0) { - // If the value is an object and not empty, create a nested div - html += ` -
    - ${key} + if ( + typeof obj[key] === "object" && + Object.keys(obj[key]).length > 0 + ) { + // If the value is an object and not empty, create a nested div + html += ` +
  • ${key}
    • - ${createHtmlList(obj[key], currentPath)} + ${createHtmlList(obj[key], currentPath, depth + 1)}
    -
    `; - } else { - // If the value is not an object or empty, create a clickable list item - html += `
  • ${key}
  • `; - } - } + } else { + // If the value is not an object or empty, create a clickable list item + html += `
  • ${key}
  • `; + } + } - return html; - } + return html; + } //const renderedList = ``; - const renderedList = createHtmlList(nestedFolders); - + let renderedList = createHtmlList(nestedFolders);