Skip to content

Commit 4dc7816

Browse files
committed
fix: catch the json file even behind a redirect
1 parent 0536c7c commit 4dc7816

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,18 +316,21 @@ async function fetchVersionSwitcherJSON(url) {
316316
} catch (err) {
317317
// if not, assume relative path and fix accordingly
318318
if (err instanceof TypeError) {
319-
result = new URL(url, window.location.origin);
319+
// workaround for redirects like https://pydata-sphinx-theme.readthedocs.io
320+
// fetch() automatically follows redirects so it should work in every builder
321+
// (RDT, GitHub actions, etc)
322+
const origin = await fetch(window.location.origin, {
323+
method: "HEAD",
324+
}).then((res) => {
325+
return res.url;
326+
});
327+
result = new URL(url, origin);
320328
} else {
321329
throw err;
322330
}
323331
}
324-
// workaround for redirects like https://pydata-sphinx-theme.readthedocs.io
325-
// fetch() automatically follows redirects so it should work in every builder
326-
// (RDT, GitHub actions, etc)
327-
const finalURL = await fetch(result, { method: "HEAD" }).then((res) => {
328-
return res.url;
329-
});
330-
const response = await fetch(finalURL);
332+
333+
const response = await fetch(result);
331334
const data = await response.json();
332335
return data;
333336
}

0 commit comments

Comments
 (0)