Skip to content

Commit 033c184

Browse files
committed
#8
Reverting to my original implementation, which currently does not handle header objects, appendix items, just courses
1 parent dce2002 commit 033c184

3 files changed

Lines changed: 3 additions & 119 deletions

File tree

book/html/404.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<!-- Book generated using mdBook -->
55
<meta charset="UTF-8">
66
<title>Page not found - Montclair Robotics Programming</title>
7-
<base href="/">
7+
<base href="/FRC-Programming-Guide/">
88

99

1010
<!-- Custom HTML head -->

book/html/theme/rnasir.js

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -120,62 +120,4 @@
120120
window.location.replace(newPath + url.search + url.hash);
121121
}
122122
}
123-
})();
124-
125-
//Repair all broken urls as of now.
126-
127-
(function () {
128-
const is404 =
129-
document.title.includes("Page not found") ||
130-
document.body.textContent.includes("could not be found");
131-
132-
if (!is404) {
133-
sessionStorage.removeItem("alreadyRedirected");
134-
return;
135-
}
136-
137-
console.warn("Detected 404 page");
138-
139-
// Only redirect once
140-
if (sessionStorage.getItem("alreadyRedirected") === "true") {
141-
console.log("Skipping redirect");
142-
return;
143-
}
144-
145-
setTimeout(() => {
146-
const segments = window.location.pathname.split("/").filter(Boolean);
147-
const base = segments[0];
148-
const rem = segments.slice(1);
149-
150-
// 2) Generic duplicate: Y/X/X/... → Y/X/...
151-
if (rem.length >= 2 && rem[0] === rem[1]) {
152-
const x = rem[0];
153-
const rest = rem.slice(2).join("/");
154-
const newPath = `/${base}/${x}/${rest}`;
155-
console.log(`🔁 Redirecting (generic dup): ${newPath}`);
156-
sessionStorage.setItem("alreadyRedirected", "true");
157-
return window.location.replace(newPath + location.search + location.hash);
158-
}
159-
160-
// 3) Y/course/X/X/... → Y/X/...
161-
if (rem.length >= 3 && rem[0] === "course" && rem[1] === rem[2]) {
162-
const x = rem[1];
163-
const rest = rem.slice(3).join("/");
164-
const newPath = `/${base}/${x}/${rest}`;
165-
console.log(`🔁 Redirecting (course dup): ${newPath}`);
166-
sessionStorage.setItem("alreadyRedirected", "true");
167-
return window.location.replace(newPath + location.search + location.hash);
168-
}
169-
170-
// 4)
171-
if (rem.length >= 2) {
172-
const x = rem[1];
173-
const rest = rem.slice(2).join("/");
174-
const newPath = `/${base}/${x}/${rest}`;
175-
console.log(`🔁 Redirecting (bad-middle): ${newPath}`);
176-
sessionStorage.setItem("alreadyRedirected", "true");
177-
return window.location.replace(newPath + location.search + location.hash);
178-
}
179-
180-
}, 62.5);
181-
})();
123+
})();

theme/rnasir.js

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -120,62 +120,4 @@
120120
window.location.replace(newPath + url.search + url.hash);
121121
}
122122
}
123-
})();
124-
125-
//Repair all broken urls as of now.
126-
127-
(function () {
128-
const is404 =
129-
document.title.includes("Page not found") ||
130-
document.body.textContent.includes("could not be found");
131-
132-
if (!is404) {
133-
sessionStorage.removeItem("alreadyRedirected");
134-
return;
135-
}
136-
137-
console.warn("Detected 404 page");
138-
139-
// Only redirect once
140-
if (sessionStorage.getItem("alreadyRedirected") === "true") {
141-
console.log("Skipping redirect");
142-
return;
143-
}
144-
145-
setTimeout(() => {
146-
const segments = window.location.pathname.split("/").filter(Boolean);
147-
const base = segments[0];
148-
const rem = segments.slice(1);
149-
150-
// 2) Generic duplicate: Y/X/X/... → Y/X/...
151-
if (rem.length >= 2 && rem[0] === rem[1]) {
152-
const x = rem[0];
153-
const rest = rem.slice(2).join("/");
154-
const newPath = `/${base}/${x}/${rest}`;
155-
console.log(`🔁 Redirecting (generic dup): ${newPath}`);
156-
sessionStorage.setItem("alreadyRedirected", "true");
157-
return window.location.replace(newPath + location.search + location.hash);
158-
}
159-
160-
// 3) Y/course/X/X/... → Y/X/...
161-
if (rem.length >= 3 && rem[0] === "course" && rem[1] === rem[2]) {
162-
const x = rem[1];
163-
const rest = rem.slice(3).join("/");
164-
const newPath = `/${base}/${x}/${rest}`;
165-
console.log(`🔁 Redirecting (course dup): ${newPath}`);
166-
sessionStorage.setItem("alreadyRedirected", "true");
167-
return window.location.replace(newPath + location.search + location.hash);
168-
}
169-
170-
// 4)
171-
if (rem.length >= 2) {
172-
const x = rem[1];
173-
const rest = rem.slice(2).join("/");
174-
const newPath = `/${base}/${x}/${rest}`;
175-
console.log(`🔁 Redirecting (bad-middle): ${newPath}`);
176-
sessionStorage.setItem("alreadyRedirected", "true");
177-
return window.location.replace(newPath + location.search + location.hash);
178-
}
179-
180-
}, 62.5);
181-
})();
123+
})();

0 commit comments

Comments
 (0)