Skip to content

Commit 3cefd73

Browse files
committed
fixes for rustdoc nightly-2023-02-07
1 parent d9d2791 commit 3cefd73

File tree

2 files changed

+17
-33
lines changed

2 files changed

+17
-33
lines changed

src/bin/builder.rs

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ fn pack_config(crate_name: &str) -> PackConfig {
2525

2626
// Remove srclinks that point to a file starting with `_`.
2727
let re_remove_hidden_src =
28-
ByteRegex::new("<a class=\"srclink\" href=\"[^\"]*/_[^\"]*\">source</a>").unwrap();
28+
ByteRegex::new("<a class=\"srclink[a-zA-Z0-9 ]*\" href=\"[^\"]*/_[^\"]*\">source</a>")
29+
.unwrap();
2930

3031
// Rewrite srclinks from `../../crate_name/foo" to "/__DOCSERVER_SRCLINK/foo".
3132
let re_rewrite_src = ByteRegex::new(&format!(
32-
"<a class=\"srclink\" href=\"(\\.\\./)+src/{}",
33+
"<a class=\"srclink([a-zA-Z0-9 ]*)\" href=\"(\\.\\./)+src/{}",
3334
&crate_name
3435
))
3536
.unwrap();
@@ -41,10 +42,6 @@ fn pack_config(crate_name: &str) -> PackConfig {
4142
// Rewrite links from `../crate_name" to "".
4243
let re_rewrite_root = ByteRegex::new(&format!("\\.\\./{}/", &crate_name)).unwrap();
4344

44-
// Rewrite links from `__REMOVE_NEXT_PATH_COMPONENT__/blah" to "".
45-
let re_remove_next_path_component =
46-
ByteRegex::new("__REMOVE_NEXT_PATH_COMPONENT__/[a-zA-Z0-9_-]+/").unwrap();
47-
4845
let re_fix_root_path = ByteRegex::new("data-root-path=\"\\.\\./").unwrap();
4946

5047
PackConfig {
@@ -70,13 +67,10 @@ fn pack_config(crate_name: &str) -> PackConfig {
7067
.as_bytes(),
7168
)
7269
.into_owned();
73-
let res = re_remove_next_path_component
74-
.replace_all(&res, &[][..])
75-
.into_owned();
7670
let res = re_rewrite_src
7771
.replace_all(
7872
&res,
79-
&b"<a class=\"srclink\" href=\"/__DOCSERVER_SRCLINK"[..],
73+
&b"<a class=\"srclink$1\" href=\"/__DOCSERVER_SRCLINK"[..],
8074
)
8175
.into_owned();
8276
let res = re_rewrite_root.replace_all(&res, &[][..]).into_owned();
@@ -236,7 +230,7 @@ fn main() -> io::Result<()> {
236230
"-Zunstable-options",
237231
"--disable-per-crate-search",
238232
"--static-root-path",
239-
"/__DOCSERVER_STATIC/",
233+
"/static/",
240234
]);
241235

242236
for (dep_name, dep) in &manifest.dependencies {
@@ -269,22 +263,7 @@ fn main() -> io::Result<()> {
269263
let doc_crate_dir = doc_dir.join(crate_name.replace('-', "_"));
270264

271265
let bytes = fs::read(doc_dir.join("search-index.js")).unwrap();
272-
fs::write(
273-
doc_crate_dir.join("search-index.js"),
274-
&bytes
275-
)
276-
.unwrap();
277-
278-
279-
// monkeypatch search.js to remove the crate name from the path.
280-
let js = fs::read(doc_dir.join("search.js")).unwrap();
281-
let monkeypatch = ByteRegex::new("return\\[displayPath,href\\]").unwrap();
282-
let js = monkeypatch.replace_all(&js, &b"href=href.slice(ROOT_PATH.length);href=ROOT_PATH+href.slice(href.indexOf('/')+1);return[displayPath,href]"[..]);
283-
fs::write(
284-
doc_crate_dir.join("search.js"),
285-
&js
286-
)
287-
.unwrap();
266+
fs::write(doc_crate_dir.join("search-index.js"), &bytes).unwrap();
288267

289268
let dir = zup_tree
290269
.pack(&doc_crate_dir, &pack_config)

src/bin/server.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,17 @@ impl Thing {
233233
x => x?,
234234
};
235235

236+
// redirect remove extra crate name in path.
237+
if path.len() > 3 && path[3] == &krate.replace('-', "_") {
238+
return self.resp_redirect(&format!(
239+
"/{}/{}/{}/{}",
240+
krate,
241+
version,
242+
flavor,
243+
path[4..].join("/")
244+
));
245+
}
246+
236247
let mut zup_path = vec!["flavors"];
237248
zup_path.extend_from_slice(&path[2..]);
238249
let mut data = match zup.read(&zup_path) {
@@ -266,12 +277,6 @@ impl Thing {
266277
let attr = c.get(1).unwrap().as_bytes();
267278
let mut link = c.get(2).unwrap().as_bytes().to_vec();
268279

269-
if link.starts_with(b"/__DOCSERVER_STATIC") {
270-
let mut link2 = b"/static".to_vec();
271-
link2.extend_from_slice(&link[19..]);
272-
link = link2
273-
}
274-
275280
if link.starts_with(b"/__DOCSERVER_SRCLINK/") {
276281
let link_path = std::str::from_utf8(&link[21..]).unwrap();
277282
let i = link_path.find('#').unwrap();

0 commit comments

Comments
 (0)