parent
70bbc76aa2
commit
db7ab52818
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@fwdekker/template",
|
"name": "@fwdekker/template",
|
||||||
"version": "2.3.1",
|
"version": "2.4.0",
|
||||||
"description": "The base template for pages on fwdekker.com.",
|
"description": "The base template for pages on fwdekker.com.",
|
||||||
"author": "Felix W. Dekker",
|
"author": "Felix W. Dekker",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
@ -47,9 +47,10 @@ const doAfterLoad = function(fun) {
|
||||||
* Fetches entries asynchronously from the website's API.
|
* Fetches entries asynchronously from the website's API.
|
||||||
*
|
*
|
||||||
* @param [highlightPath] {String} the path to highlight together with its parents
|
* @param [highlightPath] {String} the path to highlight together with its parents
|
||||||
|
* @param [cb] {Function} the callback to execute on the fetched entries, to prevent the need to re-fetch elsewhere
|
||||||
* @returns {HTMLElement} a base navigation element that will eventually be filled with contents
|
* @returns {HTMLElement} a base navigation element that will eventually be filled with contents
|
||||||
*/
|
*/
|
||||||
const nav = function(highlightPath = "") {
|
const nav = function(highlightPath = "", cb = undefined) {
|
||||||
const base = stringToHtml(
|
const base = stringToHtml(
|
||||||
`<ul><li><a href="https://fwdekker.com/">` +
|
`<ul><li><a href="https://fwdekker.com/">` +
|
||||||
`<div class="logo"><img class="logo" src="https://fwdekker.com/favicon.png" alt="FWDekker" /></div>` +
|
`<div class="logo"><img class="logo" src="https://fwdekker.com/favicon.png" alt="FWDekker" /></div>` +
|
||||||
|
@ -61,7 +62,9 @@ const nav = function(highlightPath = "") {
|
||||||
fetch("https://fwdekker.com/api/nav/")
|
fetch("https://fwdekker.com/api/nav/")
|
||||||
.then(it => it.json())
|
.then(it => it.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
json.entries.forEach(entry => base.appendChild(stringToHtml(unpackEntry(entry, "/", highlightPath), "li")))
|
if (cb !== undefined) cb(json);
|
||||||
|
|
||||||
|
json.entries.forEach(entry => base.appendChild(stringToHtml(unpackEntry(entry, "/", highlightPath), "li")));
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
console.error("Failed to fetch navigation elements", e);
|
console.error("Failed to fetch navigation elements", e);
|
||||||
|
|
Loading…
Reference in New Issue