Files
godot-docs/404.rst
Lukas Tenbrink 77a966c622 Fetch redirects based on the current URL. (#11450)
* Fetch redirects based on the current URL.

* Apply suggestions from code review

---------

Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
2025-11-16 03:21:29 +01:00

68 lines
2.5 KiB
ReStructuredText

:github_url: hide
:allow_comments: False
Page not found
==============
.. https://github.com/readthedocs/sphinx-notfound-page
.. raw:: html
<p>
Sorry, we couldn't find that page. It may have been renamed or removed
in the version of the documentation you're currently browsing.
</p>
<p>
If you're currently browsing the
<em>latest</em> version of the documentation, try browsing the
<a href="/en/stable/"><em>stable</em> version of the documentation</a>.
</p>
<p>
Alternatively, use the
<a href="#" onclick="$('#rtd-search-form [name=\\'q\\']').focus()">Search docs</a>
box on the left or <a href="/">go to the homepage</a>.
</p>
<script>
// If we were redirected to `/en/4.x/` as a result of the RTD language selector,
// redirect to `/en/stable/` instead, as English does not have a `4.x` branch.
// (For maintenance reasons, non-English languages have a single `4.x` branch
// that is the counterpart of `4.3`, `4.4`, `4.5`, and so on.)
if (window.location.pathname.includes('/en/4.x/')) {
const newUrl = window.location.pathname.replace('/en/4.x/', '/en/stable/');
window.location.replace(newUrl);
}
// Check for redirects if on a currently invalid page.
// This is done in JavaScript, as we exceed Read the Docs' limit for the amount of redirects configurable.
const currentPathSegments = window.location.pathname.split('/').filter(segment => segment !== '');
// Use the base path (e.g. "/en/latest") when available.
const currentBasePath = (currentPathSegments.length >= 2) ? ("/" + currentPathSegments.slice(0, 2).join("/")) : "/";
fetch(currentBasePath + "/_static/redirects.csv")
.then(response => response.text())
.then(csvText => {
const lines = csvText.trim().split('\n');
for (const line of lines) {
if (!line.trim()) {
continue;
}
const [from, to] = line.split(',').map(s => s.trim());
if (from && to) {
if (window.location.pathname.endsWith(from)) {
if (to.startsWith('https://')) {
window.location.replace(to);
} else {
const newUrl = window.location.href.replace(window.location.pathname, to);
window.location.replace(newUrl);
}
}
}
}
})
.catch(err => {
console.error("Couldn't fetch redirects list:", err);
});
</script>