Browse Source

Add icon for external links

Fixes #8.
master
F.W. Dekker 8 months ago
parent
commit
e5c92d3d95
Signed by: FWDekker GPG Key ID: B1B567AF58D6EE0F
  1. 6
      src/main/js/Template.js

6
src/main/js/Template.js

@ -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>`;
};

Loading…
Cancel
Save