-
Notifications
You must be signed in to change notification settings - Fork 29
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 previous releases sidebar feature for ecosystem projects #267
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
72ad11d
Fix previous releases URLs for ecosystem projects
Eric-Arellano 9affbeb
Remove JavaScript test
Eric-Arellano 50dcd38
Merge branch 'main' of https://github.com/Qiskit/qiskit_sphinx_theme …
Eric-Arellano d4b41ac
Simplify now that we have redirects to ecosystem
Eric-Arellano 57d867a
Use a utils.js file
Eric-Arellano f402a3d
Add test
Eric-Arellano 88a32f6
Merge branch 'main' of https://github.com/Qiskit/qiskit_sphinx_theme …
Eric-Arellano 51c25bd
Merge branch 'main' of https://github.com/Qiskit/qiskit_sphinx_theme …
Eric-Arellano 703757e
Update Furo too
Eric-Arellano 6e491a6
Use nofollow
Eric-Arellano 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,90 @@ | ||
const { expect, test } = require("@jest/globals"); | ||
const { describe, expect, test } = require("@jest/globals"); | ||
const { | ||
determineVersionURL: determineVersionURLPytorch, | ||
} = require("../qiskit_sphinx_theme/pytorch_base/static/js/utils.js"); | ||
const { | ||
determineVersionURL: determineVersionURLFuro, | ||
} = require("../qiskit_sphinx_theme/furo/base/static/js/utils.js"); | ||
|
||
test("dummy test to check Jest infrastructure works. Remove after", () => { | ||
expect(true).toBe(true); | ||
const checkVersionURL = (inputURL, version, expected) => { | ||
expect(determineVersionURLPytorch(inputURL, version)).toEqual(expected); | ||
expect(determineVersionURLFuro(inputURL, version)).toEqual(expected); | ||
}; | ||
|
||
describe("determineVersionURL()", () => { | ||
test("handles the /ecosystem scheme", () => { | ||
checkVersionURL( | ||
"https://qiskit.org/ecosystem/nature", | ||
"0.4", | ||
"/ecosystem/nature/stable/0.4/index.html" | ||
); | ||
checkVersionURL( | ||
"https://qiskit.org/ecosystem/finance", | ||
"0.6", | ||
"/ecosystem/finance/stable/0.6/index.html" | ||
); | ||
checkVersionURL( | ||
"https://qiskit.org/ecosystem/nature/index.html", | ||
"0.4", | ||
"/ecosystem/nature/stable/0.4/index.html" | ||
); | ||
checkVersionURL( | ||
"https://qiskit.org/ecosystem/nature/apidocs/index.html", | ||
"0.4", | ||
"/ecosystem/nature/stable/0.4/index.html" | ||
); | ||
|
||
// Already on stable URL: | ||
checkVersionURL( | ||
"https://qiskit.org/ecosystem/nature/stable/0.6/index.html", | ||
"0.4", | ||
"/ecosystem/nature/stable/0.4/index.html" | ||
); | ||
checkVersionURL( | ||
"https://qiskit.org/ecosystem/finance/stable/0.7/index.html", | ||
"0.6", | ||
"/ecosystem/finance/stable/0.6/index.html" | ||
); | ||
checkVersionURL( | ||
"https://qiskit.org/ecosystem/nature/stable/0.6/apidocs/index.html", | ||
"0.4", | ||
"/ecosystem/nature/stable/0.4/index.html" | ||
); | ||
}); | ||
|
||
test("handles Terra", () => { | ||
checkVersionURL( | ||
"https://qiskit.org/documentation", | ||
"0.4", | ||
"/documentation/stable/0.4/index.html" | ||
); | ||
checkVersionURL( | ||
"https://qiskit.org/documentation/index.html", | ||
"0.4", | ||
"/documentation/stable/0.4/index.html" | ||
); | ||
checkVersionURL( | ||
"https://qiskit.org/documentation/apidocs/index.html", | ||
"0.4", | ||
"/documentation/stable/0.4/index.html" | ||
); | ||
|
||
// Already on stable URL: | ||
checkVersionURL( | ||
"https://qiskit.org/documentation/stable/0.6/index.html", | ||
"0.4", | ||
"/documentation/stable/0.4/index.html" | ||
); | ||
checkVersionURL( | ||
"https://qiskit.org/documentation/stable/0.6/apidocs/index.html", | ||
"0.4", | ||
"/documentation/stable/0.4/index.html" | ||
); | ||
}); | ||
|
||
test("return null if the URL does not match", () => { | ||
checkVersionURL("https://qiskit.org", "0.4", null); | ||
checkVersionURL("https://qiskit.org/ecosystem", "0.4", null); | ||
checkVersionURL("file:///Users/qiskit/index.html", "0.4", null); | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Determine the URL for the version's documentation. | ||
* | ||
* @param version currentURL: The current browser's URL. | ||
* @param version string: The version of the docs, e.g. '0.4'. | ||
* @returns string | null | ||
*/ | ||
const determineVersionURL = (currentURL, version) => { | ||
// We expect URls to either be `documentation/` (Terra) or `ecosystem/<project>`. | ||
const match = currentURL.match( | ||
/(?:.*)(\/ecosystem\/\w+|\/documentation)(?:\/|$)/ | ||
); | ||
if (!match) { | ||
return null; | ||
} | ||
return `${match[1]}/stable/${version}/index.html`; | ||
}; | ||
|
||
/** | ||
* Change the browser's URL to the version's documentation. Do nothing if the current URL | ||
* is unexpected. | ||
* | ||
* @param version string: The version of the docs, e.g. '0.4'. | ||
*/ | ||
const redirectToVersion = (version) => { | ||
const result = determineVersionURL(window.location.href, version); | ||
if (!result) { | ||
console.error( | ||
`Could not determine the version URL for ${window.location.href} with version ${version}` | ||
); | ||
return; | ||
} | ||
window.location.href = result; | ||
}; | ||
|
||
if (typeof module === "undefined") { | ||
// Export utils for Sphinx usage. Assigning the values to `window` makes | ||
// the values available globally. | ||
window.redirectToVersion = redirectToVersion; | ||
} else { | ||
// Export utils for Jest testing. | ||
module.exports = { | ||
determineVersionURL, | ||
}; | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Determine the URL for the version's documentation. | ||
* | ||
* @param version currentURL: The current browser's URL. | ||
* @param version string: The version of the docs, e.g. '0.4'. | ||
* @returns string | null | ||
*/ | ||
const determineVersionURL = (currentURL, version) => { | ||
// We expect URls to either be `documentation/` (Terra) or `ecosystem/<project>`. | ||
const match = currentURL.match( | ||
/(?:.*)(\/ecosystem\/\w+|\/documentation)(?:\/|$)/ | ||
); | ||
if (!match) { | ||
return null; | ||
} | ||
return `${match[1]}/stable/${version}/index.html`; | ||
}; | ||
|
||
/** | ||
* Change the browser's URL to the version's documentation. Do nothing if the current URL | ||
* is unexpected. | ||
* | ||
* @param version string: The version of the docs, e.g. '0.4'. | ||
*/ | ||
const redirectToVersion = (version) => { | ||
const result = determineVersionURL(window.location.href, version); | ||
if (!result) { | ||
console.error( | ||
`Could not determine the version URL for ${window.location.href} with version ${version}` | ||
); | ||
return; | ||
} | ||
window.location.href = result; | ||
}; | ||
|
||
if (typeof module === "undefined") { | ||
// Export utils for Sphinx usage. Assigning the values to `window` makes | ||
// the values available globally. | ||
window.redirectToVersion = redirectToVersion; | ||
} else { | ||
// Export utils for Jest testing. | ||
module.exports = { | ||
determineVersionURL, | ||
}; | ||
} |
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.
Copy and paste of the Furo file. The Jest test is set up to ensure that the tests pass for both Furo and Pytorch.
We aren't testing that the file contents are identical between Furo and Pytorch because we may want
utils.js
to diverge. For example, maybe we add a util to Furo that is not needed for Pytorch.