diff --git a/package.json b/package.json index 2a7809e..6532d57 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fwdekker/template", - "version": "0.0.11", + "version": "0.0.12", "description": "The base template for pages on fwdekker.com.", "author": "Felix W. Dekker (https://fwdekker.com)", "license": "MIT", diff --git a/src/main/js/Template.js b/src/main/js/Template.js index 4bf3b0b..0bb34a0 100644 --- a/src/main/js/Template.js +++ b/src/main/js/Template.js @@ -36,23 +36,25 @@ export const doAfterLoad = function (fun) { * * Fetches entries asynchronously from the website's API. * - * @returns {Promise} a navigation element, eventually + * @returns {HTMLElement} a base navigation element that will eventually be filled with contents */ -export const nav = async function () { - const entries = await fetch("https://fwdekker.com/api/nav/") +export const nav = function () { + const base = h("ul", + h("li", h("a", {href: "https://fwdekker.com/"}, + h("div.logo", h("img.logo", {src: "https://fwdekker.com/favicon.png"})), + h("b", "FWDekker") + )) + ); + + fetch("https://fwdekker.com/api/nav/") .then(it => it.json()) - .then(it => it.entries) - .then(it => it.map(entry => unpackEntry(entry))) + .then(json => json.entries.forEach(entry => base.appendChild(unpackEntry(entry)))) .catch(e => { console.error("Failed to fetch navigation elements", e); return []; }); - const prefix = h("li", h("a", {href: "https://fwdekker.com/"}, - h("div.logo", h("img.logo", {src: "https://fwdekker.com/favicon.png"})), - h("b", "FWDekker") - )); - return h("nav.nav", h("ul", prefix, ...entries)); + return h("nav.nav", base); }; /** @@ -61,7 +63,7 @@ export const nav = async function () { * @param entry {Object} the entry to unpack * @returns {HTMLElement} the navigation list entry as HTML, described by its children */ -const unpackEntry = function(entry) { +const unpackEntry = function (entry) { if (entry.entries.length === 0) return h("li", h("a", {href: entry.link, innerHTML: entry.name}));