File tree Expand file tree Collapse file tree 2 files changed +30
-31
lines changed Expand file tree Collapse file tree 2 files changed +30
-31
lines changed Original file line number Diff line number Diff line change @@ -22,3 +22,33 @@ Page not found
2222 <a href =" #" onclick =" $('#rtd-search-form [name=\\'q\\']').focus()" >Search docs</a >
2323 box on the left or <a href =" /" >go to the homepage</a >.
2424 </p >
25+
26+ <script >
27+ // Check for redirects if on a currently invalid page.
28+ // This is done in JavaScript, as we exceed Read the Docs' limit for the amount of redirects configurable.
29+ // When testing this feature on a local web server, replace the URL below with just `/_static/redirects.csv`.
30+ fetch (" /en/latest/_static/redirects.csv" )
31+ .then (response => response .text ())
32+ .then (csvText => {
33+ const lines = csvText .trim ().split (' \n ' );
34+ for (const line of lines) {
35+ if (! line .trim ()) {
36+ continue ;
37+ }
38+ const [from , to ] = line .split (' ,' ).map (s => s .trim ());
39+ if (from && to) {
40+ if (window .location .pathname .endsWith (from)) {
41+ if (to .startsWith (' https://' )) {
42+ window .location .replace (to);
43+ } else {
44+ const newUrl = window .location .href .replace (window .location .pathname , to);
45+ window .location .replace (newUrl);
46+ }
47+ }
48+ }
49+ }
50+ })
51+ .catch (err => {
52+ console .error (" Couldn't fetch redirects list:" , err);
53+ });
54+ </script >
Original file line number Diff line number Diff line change @@ -297,37 +297,6 @@ const registerGiscus = function () {
297297} ;
298298
299299$ ( 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 we exceed Read the Docs' limit for the amount of redirects configurable.
304- // When testing this feature on a local web server, replace the URL below with just `/_static/redirects.csv`.
305- fetch ( "/en/latest/_static/redirects.csv" )
306- . then ( response => response . text ( ) )
307- . then ( csvText => {
308- const lines = csvText . trim ( ) . split ( '\n' ) ;
309- for ( const line of lines ) {
310- if ( ! line . trim ( ) ) {
311- continue ;
312- }
313- const [ from , to ] = line . split ( ',' ) . map ( s => s . trim ( ) ) ;
314- if ( from && to ) {
315- if ( window . location . pathname . endsWith ( from ) ) {
316- if ( to . startsWith ( 'https://' ) ) {
317- window . location . replace ( to ) ;
318- } else {
319- const newUrl = window . location . href . replace ( window . location . pathname , to ) ;
320- window . location . replace ( newUrl ) ;
321- }
322- }
323- }
324- }
325- } )
326- . catch ( err => {
327- console . error ( "Couldn't fetch redirects list:" , err ) ;
328- } ) ;
329- }
330-
331300 // Remove the search match highlights from the page, and adjust the URL in the
332301 // navigation history.
333302 const url = new URL ( location . href ) ;
You can’t perform that action at this time.
0 commit comments