mirror of
https://github.com/stan220/godot-docs.git
synced 2026-09-08 16:28:59 +00:00
Fix redirects in safari, by moving the redirect js script into the 404 page instead of checking if we're on 404 via the API.
This commit is contained in:
@@ -22,3 +22,33 @@ Page not found
|
|||||||
<a href="#" onclick="$('#rtd-search-form [name=\\'q\\']').focus()">Search docs</a>
|
<a href="#" onclick="$('#rtd-search-form [name=\\'q\\']').focus()">Search docs</a>
|
||||||
box on the left or <a href="/">go to the homepage</a>.
|
box on the left or <a href="/">go to the homepage</a>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// 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.
|
||||||
|
// When testing this feature on a local web server, replace the URL below with just `/_static/redirects.csv`.
|
||||||
|
fetch("/en/latest/_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>
|
||||||
|
|||||||
@@ -297,37 +297,6 @@ const registerGiscus = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
const httpResponseStatus = window.performance.getEntries()[0].responseStatus;
|
|
||||||
if (httpResponseStatus === 404) {
|
|
||||||
// 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.
|
|
||||||
// When testing this feature on a local web server, replace the URL below with just `/_static/redirects.csv`.
|
|
||||||
fetch("/en/latest/_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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove the search match highlights from the page, and adjust the URL in the
|
// Remove the search match highlights from the page, and adjust the URL in the
|
||||||
// navigation history.
|
// navigation history.
|
||||||
const url = new URL(location.href);
|
const url = new URL(location.href);
|
||||||
|
|||||||
Reference in New Issue
Block a user