Move nav asynchronicity into background
This commit is contained in:
parent
fcb63984d1
commit
670e2a6c3a
|
@ -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",
|
||||
|
|
|
@ -36,23 +36,25 @@ export const doAfterLoad = function (fun) {
|
|||
*
|
||||
* Fetches entries asynchronously from the website's API.
|
||||
*
|
||||
* @returns {Promise<HTMLElement>} 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);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue