tools/src/main/js/main.js

33 lines
1.1 KiB
JavaScript

// noinspection JSUnresolvedVariable
const {$, doAfterLoad, footer, header, nav, stringToHtml} = window.fwdekker;
const unpackEntry = function (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}>`;
};
doAfterLoad(() => {
$("#nav").appendChild(nav("/Tools/"));
$("#header").appendChild(header({title: "Tools", description: "An overview of tools I have created"}));
$("#footer").appendChild(footer({
vcsURL: "https://git.fwdekker.com/FWDekker/tools/",
version: "v%%VERSION_NUMBER%%"
}));
$("main").classList.remove("hidden");
fetch("https://fwdekker.com/api/nav/")
.then(it => it.json())
.then(json => json.entries.find(it => it.name === "Tools"))
.then(json => stringToHtml(`<ul>${json.entries.map(entry => unpackEntry(entry)).join("")}</ul>`, "ul"))
.then(listing => $("#listing").append(listing));
});