File tree Expand file tree Collapse file tree 1 file changed +13
-11
lines changed
src/pydata_sphinx_theme/assets/scripts Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -287,21 +287,23 @@ var setupSearchButtons = () => {
287
287
*
288
288
* @param {event } event the event that trigger the check
289
289
*/
290
- function checkPageExistsAndRedirect ( event ) {
290
+ async function checkPageExistsAndRedirect ( event ) {
291
291
// ensure we don't follow the initial link
292
292
event . preventDefault ( ) ;
293
-
294
- const currentFilePath = `${ DOCUMENTATION_OPTIONS . pagename } .html` ;
295
- const tryUrl = event . currentTarget . getAttribute ( "href" ) ;
293
+ let currentFilePath = `${ DOCUMENTATION_OPTIONS . pagename } .html` ;
294
+ let tryUrl = event . currentTarget . getAttribute ( "href" ) ;
296
295
let otherDocsHomepage = tryUrl . replace ( currentFilePath , "" ) ;
297
-
298
- fetch ( tryUrl , { method : "HEAD" } )
299
- . then ( ( ) => {
300
- location . href = tryUrl ;
301
- } ) // if the page exists, go there
302
- . catch ( ( error ) => {
296
+ try {
297
+ let head = await fetch ( tryUrl , { method : "HEAD" } ) ;
298
+ if ( head . ok ) {
299
+ location . href = tryUrl ; // the page exists, go there
300
+ } else {
303
301
location . href = otherDocsHomepage ;
304
- } ) ;
302
+ }
303
+ } catch ( err ) {
304
+ // something went wrong, probably CORS restriction, fallback to other docs homepage
305
+ location . href = otherDocsHomepage ;
306
+ }
305
307
}
306
308
307
309
/**
You can’t perform that action at this time.
0 commit comments