parent
37fa57b219
commit
e5c92d3d95
|
@ -85,16 +85,18 @@ export const nav = function (highlightPath = "") {
|
|||
*/
|
||||
const unpackEntry = function (entry, path = "/", highlightPath = "") {
|
||||
const shouldHighlight = highlightPath.startsWith(`${path + entry.name}/`);
|
||||
const isExternalLink = !entry.link.startsWith("https://fwdekker.com/") && entry.link !== "#";
|
||||
const formattedName = (isExternalLink ? "⎋ " : "") + entry.name;
|
||||
|
||||
if (entry.entries.length === 0)
|
||||
return `<li class="${shouldHighlight ? "currentPage" : ""}"><a href="${entry.link}">${entry.name}</a></li>`;
|
||||
return `<li class="${shouldHighlight ? "currentPage" : ""}"><a href="${entry.link}">${formattedName}</a></li>`;
|
||||
|
||||
const depth = path.split("/").length - 2; // -1 because count parts, then another -1 because of leading `/`
|
||||
const arrow = depth === 0 ? "▾" : "▸";
|
||||
|
||||
return "" +
|
||||
`<li class="${shouldHighlight ? "currentPage" : ""}">` +
|
||||
`<a href="${entry.link}">${entry.name} ${arrow}</a>` +
|
||||
`<a href="${entry.link}">${formattedName} ${arrow}</a>` +
|
||||
`<ul>${entry.entries.map(it => unpackEntry(it, `${path + entry.name}/`, highlightPath)).join("")}</ul>` +
|
||||
`</li>`;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue