Skip to content
This repository was archived by the owner on Apr 2, 2026. It is now read-only.

Commit e2b450b

Browse files
Fix all JS-generated links to use base path prefix
Inject __basePath variable from Site.BaseURL into page head. All JS-generated links (composition, force graphs, hub charts, taxonomy charts, packed circles, search results, arch map) now use __basePath prefix instead of hardcoded "/". Fixes #17
1 parent 54e9785 commit e2b450b

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

templates/_head.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
<link rel="preconnect" href="https://fonts.googleapis.com">
77
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
88
<link href="https://fonts.googleapis.com/css2?family=Public+Sans:wght@200;300;400;500;600;700&family=Martian+Mono:wght@300;400;500&family=Lexend+Peta:wght@400&display=swap" rel="stylesheet">
9+
<script>var __basePath = (function() { try { return new URL("{{.Site.BaseURL}}").pathname.replace(/\/$/, ""); } catch(e) { return ""; } })();</script>

templates/_main.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ window.addEventListener("load", function() {
3535
if (label.length > 16) label = label.substring(0, 14) + "..";
3636

3737
if (items[i].slug && !isLast) {
38-
svg += '<a href="/' + items[i].slug + '.html">';
38+
svg += '<a href="' + __basePath + '/' + items[i].slug + '.html">';
3939
}
4040
svg += '<rect x="' + x + '" y="' + y + '" width="' + boxW + '" height="' + boxH + '" rx="6" fill="' + fill + '" stroke="' + stroke + '" stroke-width="1"/>';
4141
svg += '<text x="' + (x + boxW / 2) + '" y="' + (y + boxH / 2 + 5) + '" text-anchor="middle" fill="' + textColor + '" font-size="12" font-family="Public Sans,system-ui,sans-serif">' + label + '</text>';
@@ -163,7 +163,7 @@ window.addEventListener("load", function() {
163163
});
164164

165165
node.on("click", function(event, d) {
166-
if (d.slug) window.location.href = "/" + d.slug + ".html";
166+
if (d.slug) window.location.href = __basePath + "/" + d.slug + ".html";
167167
});
168168

169169
simulation.on("tick", function() {
@@ -364,7 +364,7 @@ window.addEventListener("load", function() {
364364
.attr("font-family", "Public Sans,system-ui,sans-serif");
365365

366366
aoNode.on("click", function(event, d) {
367-
if (d.slug) window.location.href = "/" + d.slug + ".html";
367+
if (d.slug) window.location.href = __basePath + "/" + d.slug + ".html";
368368
});
369369

370370
aoNode.append("title").text(function(d) {
@@ -412,7 +412,7 @@ window.addEventListener("load", function() {
412412
container.className = "hp-composition";
413413
children.forEach(function(d, i) {
414414
var el = document.createElement("a");
415-
el.href = "/" + d.slug + "/index.html";
415+
el.href = __basePath + "/" + d.slug + "/index.html";
416416
el.className = "hp-comp-item";
417417
var pct = (d.value / total) * 100;
418418
el.style.flexBasis = Math.max(pct, 10) + "%";
@@ -462,15 +462,15 @@ window.addEventListener("load", function() {
462462
var cx = Math.min(hubH / 2 + 10, hubW * 0.3);
463463
var g = svg.append("g").attr("transform", "translate(" + cx + "," + (hubH / 2) + ")");
464464
var arcs = g.selectAll("path").data(pie(dist)).enter().append("path").attr("d", arc).attr("fill", function(d, i) { return hubColors[i % hubColors.length]; }).attr("stroke", "#000000").attr("stroke-width", 2).style("cursor", "pointer")
465-
.on("click", function(event, d) { window.location.href = "/" + bestKey + "/" + toSlug(d.data.name) + ".html"; });
465+
.on("click", function(event, d) { window.location.href = __basePath + "/" + bestKey + "/" + toSlug(d.data.name) + ".html"; });
466466
arcs.append("title").text(function(d) { return d.data.name + ": " + d.data.count; });
467467
g.append("text").attr("text-anchor", "middle").attr("y", 6).attr("fill", "#FFFFFF").attr("font-size", "20px").attr("font-weight", "700").attr("font-family", "Public Sans,system-ui,sans-serif").text(hubData.totalEntities || "");
468468
svg.append("text").attr("x", cx).attr("y", hubH - 4).attr("text-anchor", "middle").attr("fill", "#808080").attr("font-size", "11px").attr("font-family", "Public Sans,system-ui,sans-serif").text(dimLabels[bestKey] || bestKey);
469469
var legendX = cx + radius + 20;
470470
dist.forEach(function(d, i) {
471471
if (i >= 8) return;
472472
var ly = 16 + i * 22;
473-
var lg = svg.append("g").style("cursor", "pointer").on("click", function() { window.location.href = "/" + bestKey + "/" + toSlug(d.name) + ".html"; });
473+
var lg = svg.append("g").style("cursor", "pointer").on("click", function() { window.location.href = __basePath + "/" + bestKey + "/" + toSlug(d.name) + ".html"; });
474474
lg.append("rect").attr("x", legendX).attr("y", ly).attr("width", 10).attr("height", 10).attr("rx", 2).attr("fill", hubColors[i % hubColors.length]);
475475
lg.append("text").attr("x", legendX + 16).attr("y", ly + 9).attr("fill", "#808080").attr("font-size", "11px").attr("font-family", "Public Sans,system-ui,sans-serif").text(d.name + " (" + d.count + ")");
476476
});
@@ -523,7 +523,7 @@ window.addEventListener("load", function() {
523523
var label = d.name.replace(/ .*/, "");
524524
if (label.length > 26) label = label.substring(0, 24) + "..";
525525
var g = teSvg.append("g").style("cursor", "pointer")
526-
.on("click", function() { window.location.href = "/" + d.slug + ".html"; });
526+
.on("click", function() { window.location.href = __basePath + "/" + d.slug + ".html"; });
527527
g.append("text").attr("x", teLabelW - 6).attr("y", y + teBarH / 2 + 4).attr("text-anchor", "end")
528528
.attr("fill", "#808080").attr("font-size", "11px").attr("font-family", "Public Sans,system-ui,sans-serif").text(label);
529529
g.append("rect").attr("x", teLabelW).attr("y", y).attr("width", Math.max(teScale(d.lines), 3)).attr("height", teBarH)
@@ -556,7 +556,7 @@ window.addEventListener("load", function() {
556556
entries.forEach(function(d, i) {
557557
var y = i * (barH + gap);
558558
var label = d.name.length > 22 ? d.name.substring(0, 20) + ".." : d.name;
559-
var g = svg.append("g").style("cursor", "pointer").on("click", function() { if (taxKey) window.location.href = "/" + taxKey + "/" + toSlug(d.name) + ".html"; });
559+
var g = svg.append("g").style("cursor", "pointer").on("click", function() { if (taxKey) window.location.href = __basePath + "/" + taxKey + "/" + toSlug(d.name) + ".html"; });
560560
g.append("text").attr("x", labelW - 8).attr("y", y + barH / 2 + 4).attr("text-anchor", "end").attr("fill", "#808080").attr("font-size", "13px").attr("font-family", "Public Sans,system-ui,sans-serif").text(label);
561561
g.append("rect").attr("x", labelW).attr("y", y).attr("width", Math.max(barScale(d.count), 4)).attr("height", barH).attr("rx", 3).attr("fill", "#71B9BC").attr("opacity", 0.85);
562562
g.append("text").attr("x", labelW + Math.max(barScale(d.count), 4) + 8).attr("y", y + barH / 2 + 4).attr("fill", "#808080").attr("font-size", "12px").attr("font-family", "Public Sans,system-ui,sans-serif").text(d.count);
@@ -580,7 +580,7 @@ window.addEventListener("load", function() {
580580
d3.pack().size([aeW, aeH]).padding(4)(root);
581581
var svg = d3.select(aeChartEl).append("svg").attr("width", aeW).attr("height", aeH);
582582
var node = svg.selectAll("g").data(root.leaves()).enter().append("g").attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
583-
.style("cursor", "pointer").on("click", function(event, d) { window.location.href = "/" + "node_type/" + toSlug(d.data.name) + ".html"; });
583+
.style("cursor", "pointer").on("click", function(event, d) { window.location.href = __basePath + "/node_type/" + toSlug(d.data.name) + ".html"; });
584584
node.append("circle").attr("r", function(d) { return d.r; }).attr("fill", function(d, i) { return aeColors[i % aeColors.length]; }).attr("opacity", 0.8).attr("stroke", "#000000").attr("stroke-width", 1);
585585
node.append("text").attr("text-anchor", "middle").attr("y", -4).attr("fill", "#fff").attr("font-size", function(d) { return Math.max(10, Math.min(16, d.r / 3)) + "px"; }).attr("font-weight", "600").attr("font-family", "Public Sans,system-ui,sans-serif").text(function(d) { return d.r > 25 ? d.data.name : ""; });
586586
node.append("text").attr("text-anchor", "middle").attr("y", 12).attr("fill", "rgba(255,255,255,0.7)").attr("font-size", "11px").attr("font-family", "Public Sans,system-ui,sans-serif").text(function(d) { return d.r > 20 ? d.data.count : ""; });
@@ -609,7 +609,7 @@ window.addEventListener("load", function() {
609609
ltEntries.forEach(function(d, i) {
610610
var y = i * (ltBarH + ltGap);
611611
var label = d.name.length > 22 ? d.name.substring(0, 20) + ".." : d.name;
612-
var g = svg.append("g").style("cursor", "pointer").on("click", function() { if (ltKey) window.location.href = "/" + ltKey + "/" + toSlug(d.name) + ".html"; });
612+
var g = svg.append("g").style("cursor", "pointer").on("click", function() { if (ltKey) window.location.href = __basePath + "/" + ltKey + "/" + toSlug(d.name) + ".html"; });
613613
g.append("text").attr("x", ltLabelW - 8).attr("y", y + ltBarH / 2 + 4).attr("text-anchor", "end").attr("fill", "#808080").attr("font-size", "13px").attr("font-family", "Public Sans,system-ui,sans-serif").text(label);
614614
g.append("rect").attr("x", ltLabelW).attr("y", y).attr("width", Math.max(ltScale(d.count), 4)).attr("height", ltBarH).attr("rx", 3).attr("fill", "#71B9BC").attr("opacity", 0.85);
615615
g.append("text").attr("x", ltLabelW + Math.max(ltScale(d.count), 4) + 8).attr("y", y + ltBarH / 2 + 4).attr("fill", "#808080").attr("font-size", "12px").attr("font-family", "Public Sans,system-ui,sans-serif").text(d.count);
@@ -717,7 +717,7 @@ window.addEventListener("load", function() {
717717
for (var i = 0; i < results.length; i++) {
718718
var e = results[i].entry;
719719
var cls = i === activeIdx ? "search-result active" : "search-result";
720-
html += '<a href="/' + e.s + '.html" class="' + cls + '">';
720+
html += '<a href="' + __basePath + '/' + e.s + '.html" class="' + cls + '">';
721721
html += '<div class="search-result-title">' + escHtml(e.t) + '</div>';
722722
if (e.d) html += '<div class="search-result-desc">' + escHtml(e.d) + '</div>';
723723
html += '<div class="search-result-meta">';
@@ -747,7 +747,7 @@ window.addEventListener("load", function() {
747747
if (e.key === "Escape") { closeSearch(); }
748748
else if (e.key === "ArrowDown") { e.preventDefault(); if (activeIdx < results.length - 1) { activeIdx++; renderResults(); scrollActive(); } }
749749
else if (e.key === "ArrowUp") { e.preventDefault(); if (activeIdx > 0) { activeIdx--; renderResults(); scrollActive(); } }
750-
else if (e.key === "Enter" && activeIdx >= 0 && results[activeIdx]) { e.preventDefault(); window.location.href = "/" + results[activeIdx].entry.s + ".html"; }
750+
else if (e.key === "Enter" && activeIdx >= 0 && results[activeIdx]) { e.preventDefault(); window.location.href = __basePath + "/" + results[activeIdx].entry.s + ".html"; }
751751
});
752752

753753
function scrollActive() {

0 commit comments

Comments
 (0)