31 lines
960 B
JavaScript
31 lines
960 B
JavaScript
// noinspection JSUnresolvedVariable
|
|
const {$, doAfterLoad, stringToHtml} = window.fwdekker;
|
|
|
|
|
|
/**
|
|
* Transforms the given (nested) entry into a list item to be displayed in HTML.
|
|
*
|
|
* @param entry the entry to transform
|
|
* @returns {string} the HTML form of the given entry
|
|
*/
|
|
const unpackEntry = (entry) => {
|
|
const subEntries = entry.entries.length === 0
|
|
? ""
|
|
: `<ul>${entry.entries.map(unpackEntry).join("")}</ul>`;
|
|
|
|
return `<li><a href="${entry.link}">${entry.name}</a>${subEntries}</li>`;
|
|
};
|
|
|
|
|
|
doAfterLoad(() => {
|
|
fetch("https://fwdekker.com/api/nav/")
|
|
.then(it => it.json())
|
|
.then(json => {
|
|
const toolEntries = json.entries.find(it => it.name === "Tools").entries;
|
|
const entryHtml = stringToHtml(`<ul>${toolEntries.map(entry => unpackEntry(entry)).join("")}</ul>`, "ul");
|
|
$("#listing").append(entryHtml);
|
|
|
|
$("main").classList.remove("hidden");
|
|
});
|
|
});
|