diff --git a/src/lib/components/Navbar.svelte b/src/lib/components/Navbar.svelte index 1e60fc7..6fdbca0 100644 --- a/src/lib/components/Navbar.svelte +++ b/src/lib/components/Navbar.svelte @@ -3,6 +3,7 @@ let data = import.meta.glob("/src/routes/**/+page.md"); let paths = data; + export let items; /** * @param {Record Promise>} paths @@ -37,24 +38,52 @@ } 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 renderNestedList(node, prefix = "") { + // return Object.keys(node) + // .map((key) => { + // const fullPath = `${prefix}/${key}`; + // return `
  • ${key}
      ${renderNestedList( + // node[key], + // fullPath + // )}
  • `; + // }) + // .join(""); + // } + + function createHtmlList(obj, parentPath = '') { + let html = ''; + + 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} +
      + ${createHtmlList(obj[key], currentPath)} +
    +
    + `; + } else { + // If the value is not an object or empty, create a clickable list item + html += `
  • ${key}
  • `; + } + } + + return html; + } + + //const renderedList = ``; + const renderedList = createHtmlList(nestedFolders); - const renderedList = ``;