mirror of
https://github.com/JonasunderscoreJones/wiki.jonasjones.dev.git
synced 2025-10-22 13:59:19 +02:00
Code Refactor and Style adjustments
- Refactored Code - Adjusted hierarchy bullet point text sizes
This commit is contained in:
parent
d918531853
commit
c539c01afb
1 changed files with 22 additions and 38 deletions
|
@ -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">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue