Browse Source

Move nav asynchronicity into background

master v0.0.12
F.W. Dekker 2 years ago
parent
commit
670e2a6c3a
Signed by: FWDekker GPG Key ID: B1B567AF58D6EE0F
  1. 2
      package.json
  2. 24
      src/main/js/Template.js

2
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",

24
src/main/js/Template.js

@ -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);
};
/**
@ -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}));

Loading…
Cancel
Save