Skip to content
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

[docs] make search redirect relatively to current version (fixes #25860) #28097

Merged
merged 1 commit into from
Aug 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions doc/source/_static/js/docsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ const searchInput = document.getElementById("search-input");
searchInput.addEventListener("keydown", function (e) {
if (e.code === "Enter") {
var searchForm = document.getElementsByClassName("bd-search")[0];

const text = searchInput.value;
searchForm.action = "https://docs.ray.io/en/latest/search.html?q=" + text;

const pageUrl = window.location.href
const res = pageUrl.split("/");
const version = (res.length <= 3) ? "latest" : res[4];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about "master"?

Copy link
Contributor Author

@maxpumperla maxpumperla Aug 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@richardliaw this catches edge cases for the docs URL like localhost:8000 and defaults to latest for search in those cases, and otherwise extracts the proper version such as releases-1.13.0 or master.


searchForm.action = "https://docs.ray.io/en/" + version + "/search.html?q=" + text;
searchForm.submit();
}
});