Skip to content

Commit 77a966c

Browse files
IvorforceCalinou
andauthored
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 <[email protected]>
1 parent b197efa commit 77a966c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

404.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ Page not found
3535
3636
// Check for redirects if on a currently invalid page.
3737
// This is done in JavaScript, as we exceed Read the Docs' limit for the amount of redirects configurable.
38-
// When testing this feature on a local web server, replace the URL below with just `/_static/redirects.csv`.
39-
fetch("/en/latest/_static/redirects.csv")
38+
39+
const currentPathSegments = window.location.pathname.split('/').filter(segment => segment !== '');
40+
// Use the base path (e.g. "/en/latest") when available.
41+
const currentBasePath = (currentPathSegments.length >= 2) ? ("/" + currentPathSegments.slice(0, 2).join("/")) : "/";
42+
43+
fetch(currentBasePath + "/_static/redirects.csv")
4044
.then(response => response.text())
4145
.then(csvText => {
4246
const lines = csvText.trim().split('\n');

0 commit comments

Comments
 (0)