Skip to content

Commit

Permalink
fixes for rustdoc nightly-2023-02-07
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio committed Feb 13, 2023
1 parent d9d2791 commit 3cefd73
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 33 deletions.
33 changes: 6 additions & 27 deletions src/bin/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("<a class=\"srclink\" href=\"[^\"]*/_[^\"]*\">source</a>").unwrap();
ByteRegex::new("<a class=\"srclink[a-zA-Z0-9 ]*\" href=\"[^\"]*/_[^\"]*\">source</a>")
.unwrap();

// Rewrite srclinks from `../../crate_name/foo" to "/__DOCSERVER_SRCLINK/foo".
let re_rewrite_src = ByteRegex::new(&format!(
"<a class=\"srclink\" href=\"(\\.\\./)+src/{}",
"<a class=\"srclink([a-zA-Z0-9 ]*)\" href=\"(\\.\\./)+src/{}",
&crate_name
))
.unwrap();
Expand All @@ -41,10 +42,6 @@ fn pack_config(crate_name: &str) -> 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 {
Expand All @@ -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"<a class=\"srclink\" href=\"/__DOCSERVER_SRCLINK"[..],
&b"<a class=\"srclink$1\" href=\"/__DOCSERVER_SRCLINK"[..],
)
.into_owned();
let res = re_rewrite_root.replace_all(&res, &[][..]).into_owned();
Expand Down Expand Up @@ -236,7 +230,7 @@ fn main() -> io::Result<()> {
"-Zunstable-options",
"--disable-per-crate-search",
"--static-root-path",
"/__DOCSERVER_STATIC/",
"/static/",
]);

for (dep_name, dep) in &manifest.dependencies {
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 11 additions & 6 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 3cefd73

Please sign in to comment.