diff --git a/src/bin/builder.rs b/src/bin/builder.rs index 72b3141..d01c09d 100644 --- a/src/bin/builder.rs +++ b/src/bin/builder.rs @@ -25,11 +25,12 @@ fn pack_config(crate_name: &str) -> PackConfig { // Remove srclinks that point to a file starting with `_`. let re_remove_hidden_src = - ByteRegex::new("source").unwrap(); + ByteRegex::new("source") + .unwrap(); // Rewrite srclinks from `../../crate_name/foo" to "/__DOCSERVER_SRCLINK/foo". let re_rewrite_src = ByteRegex::new(&format!( - " PackConfig { // Rewrite links from `../crate_name" to "". let re_rewrite_root = ByteRegex::new(&format!("\\.\\./{}/", &crate_name)).unwrap(); - // Rewrite links from `__REMOVE_NEXT_PATH_COMPONENT__/blah" to "". - let re_remove_next_path_component = - ByteRegex::new("__REMOVE_NEXT_PATH_COMPONENT__/[a-zA-Z0-9_-]+/").unwrap(); - let re_fix_root_path = ByteRegex::new("data-root-path=\"\\.\\./").unwrap(); PackConfig { @@ -70,13 +67,10 @@ fn pack_config(crate_name: &str) -> PackConfig { .as_bytes(), ) .into_owned(); - let res = re_remove_next_path_component - .replace_all(&res, &[][..]) - .into_owned(); let res = re_rewrite_src .replace_all( &res, - &b" io::Result<()> { "-Zunstable-options", "--disable-per-crate-search", "--static-root-path", - "/__DOCSERVER_STATIC/", + "/static/", ]); for (dep_name, dep) in &manifest.dependencies { @@ -269,22 +263,7 @@ fn main() -> io::Result<()> { let doc_crate_dir = doc_dir.join(crate_name.replace('-', "_")); let bytes = fs::read(doc_dir.join("search-index.js")).unwrap(); - fs::write( - doc_crate_dir.join("search-index.js"), - &bytes - ) - .unwrap(); - - - // monkeypatch search.js to remove the crate name from the path. - let js = fs::read(doc_dir.join("search.js")).unwrap(); - let monkeypatch = ByteRegex::new("return\\[displayPath,href\\]").unwrap(); - let js = monkeypatch.replace_all(&js, &b"href=href.slice(ROOT_PATH.length);href=ROOT_PATH+href.slice(href.indexOf('/')+1);return[displayPath,href]"[..]); - fs::write( - doc_crate_dir.join("search.js"), - &js - ) - .unwrap(); + fs::write(doc_crate_dir.join("search-index.js"), &bytes).unwrap(); let dir = zup_tree .pack(&doc_crate_dir, &pack_config) diff --git a/src/bin/server.rs b/src/bin/server.rs index aaee747..0514ab3 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -233,6 +233,17 @@ impl Thing { x => x?, }; + // redirect remove extra crate name in path. + if path.len() > 3 && path[3] == &krate.replace('-', "_") { + return self.resp_redirect(&format!( + "/{}/{}/{}/{}", + krate, + version, + flavor, + path[4..].join("/") + )); + } + let mut zup_path = vec!["flavors"]; zup_path.extend_from_slice(&path[2..]); let mut data = match zup.read(&zup_path) { @@ -266,12 +277,6 @@ impl Thing { let attr = c.get(1).unwrap().as_bytes(); let mut link = c.get(2).unwrap().as_bytes().to_vec(); - if link.starts_with(b"/__DOCSERVER_STATIC") { - let mut link2 = b"/static".to_vec(); - link2.extend_from_slice(&link[19..]); - link = link2 - } - if link.starts_with(b"/__DOCSERVER_SRCLINK/") { let link_path = std::str::from_utf8(&link[21..]).unwrap(); let i = link_path.find('#').unwrap();