From e329478f71df8aab01c3e86a55cd438b7f2d1d51 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Mon, 22 Jan 2024 21:02:42 +0000 Subject: [PATCH 1/3] Don't try to populate version switcher on static sites --- .../assets/scripts/pydata-sphinx-theme.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js b/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js index b0e65ab1d..d4da07905 100644 --- a/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js +++ b/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js @@ -347,6 +347,14 @@ async function fetchVersionSwitcherJSON(url) { var result = new URL(url); } catch (err) { if (err instanceof TypeError) { + if (!window.location.origin) { + // window.locaiton.origin is null for local static sites + // (ie. window.location.protocol == 'file:') + // + // TODO: Fix this to return the static version switcher by working out + // how to get the correct path to the switcher JSON file on local static builds + return null; + } // assume we got a relative path, and fix accordingly. But first, we need to // use `fetch()` to follow redirects so we get the correct final base URL const origin = await fetch(window.location.origin, { method: "HEAD" }); @@ -556,9 +564,11 @@ if (hasVersionsJSON && (hasSwitcherMenu || wantsWarningBanner)) { const data = await fetchVersionSwitcherJSON( DOCUMENTATION_OPTIONS.theme_switcher_json_url ); - populateVersionSwitcher(data, versionSwitcherBtns); - if (wantsWarningBanner) { - showVersionWarningBanner(data); + if (data) { + populateVersionSwitcher(data, versionSwitcherBtns); + if (wantsWarningBanner) { + showVersionWarningBanner(data); + } } } From a79e3aabb18e8c78d61fd9616eb15b7dc0eb611b Mon Sep 17 00:00:00 2001 From: David Stansby Date: Mon, 22 Jan 2024 21:04:06 +0000 Subject: [PATCH 2/3] Fix comment spelling --- src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js b/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js index d4da07905..6e10de2d0 100644 --- a/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js +++ b/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js @@ -348,7 +348,7 @@ async function fetchVersionSwitcherJSON(url) { } catch (err) { if (err instanceof TypeError) { if (!window.location.origin) { - // window.locaiton.origin is null for local static sites + // window.location.origin is null for local static sites // (ie. window.location.protocol == 'file:') // // TODO: Fix this to return the static version switcher by working out From 57c708993afe33636a9f105933de1010b2380a83 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Mon, 22 Jan 2024 16:58:34 -0600 Subject: [PATCH 3/3] Update src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js --- src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js b/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js index 6e10de2d0..64b8269da 100644 --- a/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js +++ b/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js @@ -564,6 +564,8 @@ if (hasVersionsJSON && (hasSwitcherMenu || wantsWarningBanner)) { const data = await fetchVersionSwitcherJSON( DOCUMENTATION_OPTIONS.theme_switcher_json_url ); + // TODO: remove the `if(data)` once the `return null` is fixed within fetchVersionSwitcherJSON. + // We don't really want the switcher and warning bar to silently not work. if (data) { populateVersionSwitcher(data, versionSwitcherBtns); if (wantsWarningBanner) {