|
1 |
| - |
2 | 1 | // Handle page scroll and adjust sidebar accordingly.
|
3 | 2 |
|
4 | 3 | // Each page has two scrolls: the main scroll, which is moving the content of the page;
|
@@ -298,6 +297,37 @@ const registerGiscus = function () {
|
298 | 297 | };
|
299 | 298 |
|
300 | 299 | $(document).ready(() => {
|
| 300 | + const httpResponseStatus = window.performance.getEntries()[0].responseStatus; |
| 301 | + if (httpResponseStatus === 404) { |
| 302 | + // Check for redirects if on a currently invalid page. |
| 303 | + // This is done in JavaScript, as Read the Docs' own redirect functionality |
| 304 | + // is unreliable with large amounts of redirects defined. |
| 305 | + fetch("https://raw.githubusercontent.com/godotengine/godot-docs/refs/heads/master/_tools/redirects/redirects.csv") |
| 306 | + .then(response => response.text()) |
| 307 | + .then(csvText => { |
| 308 | + const lines = csvText.trim().split('\n'); |
| 309 | + const redirects = {}; |
| 310 | + for (const line of lines) { |
| 311 | + if (!line.trim()) { |
| 312 | + continue; |
| 313 | + } |
| 314 | + const [from, to] = line.split(',').map(s => s.trim()); |
| 315 | + if (from && to) { |
| 316 | + redirects[from] = to; |
| 317 | + } |
| 318 | + } |
| 319 | + |
| 320 | + if (redirects.hasOwnProperty(window.location.pathname)) { |
| 321 | + const newUrl = window.location.href.replace(window.location.pathname, redirects[window.location.pathname]); |
| 322 | + console.log(`Redirecting to: ${newUrl}`); |
| 323 | + window.location.replace(newUrl); |
| 324 | + } |
| 325 | + }) |
| 326 | + .catch(err => { |
| 327 | + console.error("Couldn't fetch redirects list:", err); |
| 328 | + }); |
| 329 | + } |
| 330 | + |
301 | 331 | // Remove the search match highlights from the page, and adjust the URL in the
|
302 | 332 | // navigation history.
|
303 | 333 | const url = new URL(location.href);
|
|
0 commit comments