Code Refactor and Style adjustments

- Refactored Code
- Adjusted hierarchy bullet point text sizes
This commit is contained in:
Jonas_Jones 2023-10-02 18:28:18 +02:00
parent d918531853
commit c539c01afb

View file

@ -3,7 +3,6 @@
let data = import.meta.glob("/src/routes/**/+page.md");
let paths = data;
export let items;
/**
* @param {Record<string, () => Promise<unknown>>} 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 `<li><a href="${fullPath}">${key}</a><ul>${renderNestedList(
// node[key],
// fullPath
// )}</ul></li>`;
// })
// .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 += `
<details>
<summary><a href="/${currentPath}">${key}</a></summary>
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 += `
<li><h${depth + 3}><a href="/${currentPath}">${key}</a></h${
depth + 3
}></li>
<ul>
${createHtmlList(obj[key], currentPath)}
${createHtmlList(obj[key], currentPath, depth + 1)}
</ul>
</details>
`;
} else {
// If the value is not an object or empty, create a clickable list item
html += `<li><a href="/${currentPath}">${key}</a></li>`;
}
}
} else {
// If the value is not an object or empty, create a clickable list item
html += `<li><a href="/${currentPath}">${key}</a></li>`;
}
}
return html;
}
return html;
}
//const renderedList = `<ul>${renderNestedList(nestedFolders)}</ul>`;
const renderedList = createHtmlList(nestedFolders);
let renderedList = createHtmlList(nestedFolders);
</script>
<div class="container navbar">