-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix wrong switcher JSON loaded for dev docs #2048
Open
drammock
wants to merge
3
commits into
pydata:main
Choose a base branch
from
drammock:fix-stable-banner-button
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+25
−11
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -406,23 +406,31 @@ async function checkPageExistsAndRedirect(event) { | |
* @param {string} url The URL to load version switcher entries from. | ||
*/ | ||
async function fetchVersionSwitcherJSON(url) { | ||
const currentPath = getCurrentUrlPath(); | ||
// first check if it's a valid URL | ||
try { | ||
var result = new URL(url); | ||
} catch (err) { | ||
if (err instanceof TypeError) { | ||
if (!window.location.origin) { | ||
// 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 | ||
// 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. | ||
if (window.location.protocol == "file:") { | ||
// Here instead of returning `null` we work out what the file path would be | ||
// anyway (same code path as for served docs), as a convenience to folks who | ||
// routinely disable CORS when they boot up their browser. | ||
console.info( | ||
"[PST] looks like you're viewing this site from a local filesystem, so " + | ||
"the version switcher won't work unless you've disabled CORS. See " + | ||
"https://pydata-sphinx-theme.readthedocs.io/en/stable/user_guide/version-dropdown.html", | ||
); | ||
} | ||
// 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 | ||
Comment on lines
-422
to
-423
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this comment about using |
||
const origin = await fetch(window.location.origin, { method: "HEAD" }); | ||
result = new URL(url, origin.url); | ||
const cutoff = window.location.href.indexOf(currentPath); | ||
// cutoff == -1 can happen e.g. on the homepage of locally served docs, where you | ||
// get something like http://127.0.0.1:8000/ (no trailing `index.html`) | ||
const origin = | ||
cutoff == -1 | ||
? window.location.href | ||
: window.location.href.substring(0, cutoff); | ||
result = new URL(url, origin); | ||
} else { | ||
// something unexpected happened | ||
throw err; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we print that, or a link to that in the console when we see the
file://
protocol ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered doing a console.log but then I thought: pointing folks to this docs page is way easier than explaining how to view browser console. So to me seemed not worth it but I don't mind adding it if you think is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wait I misunderstood you. You're thinking about folks who already are checking browser console when something goes wrong. Yeah, probably worth adding it for their benefit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's what I meant.
I was also going to point out, if we detect this we could literally fill the version switcher itself with this text; but that may be overkill.