Skip to content

Commit 620f3c1

Browse files
authored
Merge pull request #4 from Coding-Autopilot-System/codex/implement-features-as-per-codex-instructions-929rq0
Harden site link resolution for GitHub Pages
2 parents 47c6fca + 4f18fbc commit 620f3c1

2 files changed

Lines changed: 35 additions & 16 deletions

File tree

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ graph LR
6969
[`docs/00-executive-overview.md`](docs/00-executive-overview.md).
7070

7171
## Using the static site
72-
Open [`docs/site/index.html`](docs/site/index.html) to browse a minimal HTML version of the content with navigation and search.
73-
Open [`site/index.html`](site/index.html) to browse a minimal HTML version of the content with navigation and search.
72+
Open [`docs/index.html`](docs/index.html) to browse a minimal HTML version of the content with navigation and search.
7473

7574
## Repo structure
7675
The repository includes:

docs/assets/app.js

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,40 @@
1-
const pages = [
2-
{ title: "Overview", href: "pages/overview.html" },
3-
{ title: "Service Definition", href: "pages/service-definition.html" },
4-
{ title: "Operating Model", href: "pages/operating-model.html" },
5-
{ title: "Architecture", href: "pages/architecture.html" },
6-
{ title: "KPIs", href: "pages/kpis.html" },
7-
{ title: "Roadmap", href: "pages/roadmap.html" },
8-
{ title: "Runbooks", href: "pages/runbooks.html" },
9-
{ title: "Templates", href: "pages/templates.html" },
10-
{ title: "Hybrid", href: "pages/hybrid.html" }
1+
const pageDefinitions = [
2+
{ title: "Overview", path: "pages/overview.html" },
3+
{ title: "Service Definition", path: "pages/service-definition.html" },
4+
{ title: "Operating Model", path: "pages/operating-model.html" },
5+
{ title: "Architecture", path: "pages/architecture.html" },
6+
{ title: "KPIs", path: "pages/kpis.html" },
7+
{ title: "Roadmap", path: "pages/roadmap.html" },
8+
{ title: "Runbooks", path: "pages/runbooks.html" },
9+
{ title: "Templates", path: "pages/templates.html" },
10+
{ title: "Hybrid", path: "pages/hybrid.html" }
1111
];
1212

13+
function getBasePath() {
14+
let path = window.location.pathname;
15+
if (path.endsWith("/")) {
16+
path = path.slice(0, -1);
17+
}
18+
if (path.endsWith("/index.html")) {
19+
path = path.slice(0, -"/index.html".length);
20+
}
21+
if (path.includes("/pages/")) {
22+
path = path.split("/pages/")[0];
23+
}
24+
return path || "";
25+
}
26+
27+
function resolveHref(targetPath) {
28+
const basePath = getBasePath();
29+
const trimmedBase = basePath.replace(/\/$/, "");
30+
return `${trimmedBase}/${targetPath}`;
31+
}
32+
1333
function buildNav() {
1434
const nav = document.getElementById("nav-links");
15-
pages.forEach((page) => {
35+
pageDefinitions.forEach((page) => {
1636
const link = document.createElement("a");
17-
link.href = page.href;
37+
link.href = resolveHref(page.path);
1838
link.textContent = page.title;
1939
nav.appendChild(link);
2040
});
@@ -25,14 +45,14 @@ function setupSearch() {
2545
if (!input) return;
2646
input.addEventListener("input", (event) => {
2747
const query = event.target.value.toLowerCase();
28-
const results = pages.filter((page) =>
48+
const results = pageDefinitions.filter((page) =>
2949
page.title.toLowerCase().includes(query)
3050
);
3151
const nav = document.getElementById("nav-links");
3252
nav.innerHTML = "";
3353
results.forEach((page) => {
3454
const link = document.createElement("a");
35-
link.href = page.href;
55+
link.href = resolveHref(page.path);
3656
link.textContent = page.title;
3757
nav.appendChild(link);
3858
});

0 commit comments

Comments
 (0)