tools/src/main/js/main.js

45 lines
1.4 KiB
JavaScript

// noinspection JSUnresolvedVariable
const {$, doAfterLoad, footer, header, nav, stringToHtml} = window.fwdekker;
/**
* Transforms the given (nested) entry into a list item to be displayed in HTML.
*
* @param entry the entry to transform
* @param depth the current level of nesting
* @returns {string} the HTML form of the given entry
*/
const unpackEntry = (entry, depth = 0) => {
const subEntries = entry.entries.length === 0
? ""
: `<ul>` + entry.entries.map(it => unpackEntry(it, depth + 1)).join("") + `</ul>`;
return "" +
`<h${depth + 4}>` +
`<a href="${entry.link}">${entry.name}</a>` +
subEntries +
`</h${depth + 4}>`;
};
/**
* Displays the given entries on the page.
*
* @param entries the entries to display
*/
const showEntries = entries => {
const toolEntries = entries.entries.find(it => it.name === "Tools").entries;
const entryHtml = stringToHtml(`<ul>${toolEntries.map(entry => unpackEntry(entry)).join("")}</ul>`, "ul");
$("#listing").append(entryHtml);
};
doAfterLoad(() => {
$("#nav").appendChild(nav("/Tools/", showEntries));
$("#header").appendChild(header({title: "Tools", description: "An overview of tools I have created"}));
$("#footer").appendChild(footer({
vcsURL: "https://git.fwdekker.com/tools/tools/",
version: "v%%VERSION_NUMBER%%"
}));
$("main").classList.remove("hidden");
});