Add icon for external links

Fixes #8.
This commit is contained in:
Florine W. Dekker 2021-04-13 19:59:51 +02:00
parent 37fa57b219
commit e5c92d3d95
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
1 changed files with 4 additions and 2 deletions

View File

@ -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 ? "&#9662;" : "&#9656;";
return "" +
`<li class="${shouldHighlight ? "currentPage" : ""}">` +
`<a href="${entry.link}">${entry.name} ${arrow}</a>` +
`<a href="${entry.link}">${formattedName}&nbsp;${arrow}</a>` +
`<ul>${entry.entries.map(it => unpackEntry(it, `${path + entry.name}/`, highlightPath)).join("")}</ul>` +
`</li>`;
};