diff --git a/src/web/crate_details.rs b/src/web/crate_details.rs index cc8d99925..2dbf93fda 100644 --- a/src/web/crate_details.rs +++ b/src/web/crate_details.rs @@ -1307,13 +1307,15 @@ mod tests { fn run_check_links( env: &TestEnvironment, - url: &str, + url_start: &str, + url_end: &str, extra: &str, should_contain_redirect: bool, ) { run_check_links_redir( env, - url, + url_start, + url_end, extra, should_contain_redirect, should_contain_redirect, @@ -1322,18 +1324,30 @@ mod tests { fn run_check_links_redir( env: &TestEnvironment, - url: &str, + url_start: &str, + url_end: &str, extra: &str, should_contain_redirect: bool, ajax_should_contain_redirect: bool, ) { - let response = env.frontend().get(url).send().unwrap(); + let response = env + .frontend() + .get(&format!("{url_start}{url_end}")) + .send() + .unwrap(); assert!(response.status().is_success()); let list1 = check_links(response.text().unwrap(), false, should_contain_redirect); // Same test with AJAX endpoint. + let (start, extra_name) = if url_start.starts_with("/crate/") { + ("", "/crate") + } else { + ("/crate", "") + }; let response = env .frontend() - .get(&format!("/-/menus/platforms{url}{extra}")) + .get(&format!( + "{start}{url_start}/menus/platforms{extra_name}{url_end}{extra}" + )) .send() .unwrap(); assert!(response.status().is_success()); @@ -1365,17 +1379,31 @@ mod tests { // FIXME: For some reason, there are target-redirects on non-AJAX lists on docs.rs // crate pages other than the "default" one. - run_check_links_redir(env, "/crate/dummy/0.4.0/features", "", true, false); - run_check_links_redir(env, "/crate/dummy/0.4.0/builds", "", true, false); - run_check_links_redir(env, "/crate/dummy/0.4.0/source/", "", true, false); - run_check_links_redir(env, "/crate/dummy/0.4.0/source/README.md", "", true, false); - - run_check_links(env, "/crate/dummy/0.4.0", "", false); - run_check_links(env, "/dummy/latest/dummy", "/", true); - run_check_links(env, "/dummy/0.4.0/x86_64-pc-windows-msvc/dummy", "/", true); + run_check_links_redir(env, "/crate/dummy/0.4.0", "/features", "", true, false); + run_check_links_redir(env, "/crate/dummy/0.4.0", "/builds", "", true, false); + run_check_links_redir(env, "/crate/dummy/0.4.0", "/source/", "", true, false); + run_check_links_redir( + env, + "/crate/dummy/0.4.0", + "/source/README.md", + "", + true, + false, + ); + + run_check_links(env, "/crate/dummy/0.4.0", "", "/", false); + run_check_links(env, "/dummy/latest", "/dummy", "/", true); + run_check_links( + env, + "/dummy/0.4.0", + "/x86_64-pc-windows-msvc/dummy", + "/", + true, + ); run_check_links( env, - "/dummy/0.4.0/x86_64-pc-windows-msvc/dummy/struct.A.html", + "/dummy/0.4.0", + "/x86_64-pc-windows-msvc/dummy/struct.A.html", "/", true, ); diff --git a/src/web/routes.rs b/src/web/routes.rs index a2ef1db5b..a5b4485c1 100644 --- a/src/web/routes.rs +++ b/src/web/routes.rs @@ -237,51 +237,47 @@ pub(super) fn build_axum_routes() -> AxumRouter { get_internal(super::source::source_browser_handler), ) .route( - "/-/menus/platforms/crate/:name/:version", + "/crate/:name/:version/menus/platforms/crate/", get_internal(super::crate_details::get_all_platforms_root), ) .route( - "/-/menus/platforms/crate/:name/:version/features", + "/crate/:name/:version/menus/platforms/crate/features", get_internal(super::crate_details::get_all_platforms_root), ) .route( - "/-/menus/platforms/crate/:name/:version/builds", + "/crate/:name/:version/menus/platforms/crate/builds", get_internal(super::crate_details::get_all_platforms_root), ) .route( - "/-/menus/platforms/crate/:name/:version/builds/*path", + "/crate/:name/:version/menus/platforms/crate/builds/*path", get_internal(super::crate_details::get_all_platforms_root), ) .route( - "/-/menus/platforms/crate/:name/:version/source/", + "/crate/:name/:version/menus/platforms/crate/source/", get_internal(super::crate_details::get_all_platforms_root), ) .route( - "/-/menus/platforms/crate/:name/:version/source/*path", + "/crate/:name/:version/menus/platforms/crate/source/*path", get_internal(super::crate_details::get_all_platforms_root), ) .route( - "/-/menus/platforms/crate/:name/:version/:target", + "/crate/:name/:version/menus/platforms/:target", get_internal(super::crate_details::get_all_platforms), ) .route( - "/-/menus/platforms/crate/:name/:version/:target/*path", + "/crate/:name/:version/menus/platforms/:target/*path", get_internal(super::crate_details::get_all_platforms), ) .route( - "/-/menus/platforms/:name/:version/", + "/crate/:name/:version/menus/platforms/", get_internal(super::crate_details::get_all_platforms), ) .route( - "/-/menus/platforms/:name/:version/:target/", + "/crate/:name/:version/menus/platforms/:target/", get_internal(super::crate_details::get_all_platforms), ) .route( - "/-/menus/platforms/:name/:version/:target/*path", - get_internal(super::crate_details::get_all_platforms), - ) - .route( - "/-/menus/releases/:name", + "/crate/:name/:version/menus/releases", get_internal(super::crate_details::get_all_releases), ) .route( diff --git a/src/web/rustdoc.rs b/src/web/rustdoc.rs index 19ecc7e15..fc0174d64 100644 --- a/src/web/rustdoc.rs +++ b/src/web/rustdoc.rs @@ -2259,7 +2259,7 @@ mod test { // test rustdoc pages stay on the documentation let page = kuchikiki::parse_html().one( env.frontend() - .get("/-/menus/releases/hexponent") + .get("/crate/hexponent/0.3.1/menus/releases") .send()? .text()?, ); diff --git a/static/menu.js b/static/menu.js index 686f75bee..c84e0eb3c 100644 --- a/static/menu.js +++ b/static/menu.js @@ -20,7 +20,14 @@ function loadAjaxMenu(menu, id, msg, path, extra) { // We're not in a documentation page, so no need to do anything. return; } - const crateName = window.location.pathname.split('/')[1]; + const parts = window.location.pathname.split("/"); + let crateName = parts[1]; + let version = parts[2]; + if (crateName === "crate") { + crateName = parts[2]; + version = parts[3]; + path += "/crate"; + } const xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (xhttp.readyState !== XMLHttpRequest.DONE) { @@ -33,7 +40,8 @@ function loadAjaxMenu(menu, id, msg, path, extra) { document.getElementById(id).innerHTML = `Failed to load ${msg}`; } }; - xhttp.open("GET", `/-/menus/${path}/${crateName}${extra}`, true); + console.log(extra, path); + xhttp.open("GET", `/crate/${crateName}/${version}/menus/${path}${extra}`, true); xhttp.send(); }; @@ -88,13 +96,15 @@ function loadAjaxMenu(menu, id, msg, path, extra) { if (newMenu.querySelector("#releases-list")) { loadAjaxMenu(newMenu, "releases-list", "release list", "releases", ""); } else if (newMenu.querySelector("#platforms")) { + const parts = window.location.pathname.split("/"); + const startFrom = parts[1] === "crate" ? 4 : 3; loadAjaxMenu( newMenu, "platforms", "platforms list", "platforms", - // We get everything except the first crate name. - "/" + window.location.pathname.split("/").slice(2).join("/") + // We get everything except the first crate name and the version. + "/" + parts.slice(startFrom).join("/") ); } }