Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,17 @@ mod test {
// with or without slash
assert_redirect("/proc-macro", target, web)?;
assert_redirect("/proc-macro/", target, web)?;

let target = "https://doc.rust-lang.org/nightly/nightly-rustc/";
// with or without slash
assert_redirect("/rustc", target, web)?;
assert_redirect("/rustc/", target, web)?;

let target = "https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/";
// with or without slash
assert_redirect("/rustdoc", target, web)?;
assert_redirect("/rustdoc/", target, web)?;

Ok(())
})
}
Expand Down
14 changes: 12 additions & 2 deletions src/web/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,23 @@ pub(super) fn build_routes() -> Routes {
for redirect in DOC_RUST_LANG_ORG_REDIRECTS {
routes.internal_page(
&format!("/{}", redirect),
super::rustdoc::RustLangRedirector::new(redirect),
super::rustdoc::RustLangRedirector::new("stable", redirect),
);
}
// redirect proc-macro to proc_macro
routes.internal_page(
"/proc-macro",
super::rustdoc::RustLangRedirector::new("proc_macro"),
super::rustdoc::RustLangRedirector::new("stable", "proc_macro"),
);
// redirect rustc to nightly rustc docs
routes.internal_page(
"/rustc",
super::rustdoc::RustLangRedirector::new("nightly", "nightly-rustc"),
);
// redirect rustdoc to nightly rustdoc docs
routes.internal_page(
"/rustdoc",
super::rustdoc::RustLangRedirector::new("nightly", "nightly-rustc/rustdoc"),
);

routes
Expand Down
9 changes: 4 additions & 5 deletions src/web/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ pub struct RustLangRedirector {
}

impl RustLangRedirector {
pub fn new(target: &'static str) -> Self {
let url = iron::url::Url::parse("https://doc.rust-lang.org/stable/")
.expect("failed to parse rust-lang.org base URL")
.join(target)
.expect("failed to append crate name to rust-lang.org base URL");
pub fn new(version: &str, target: &str) -> Self {
let url =
iron::url::Url::parse(&format!("https://doc.rust-lang.org/{}/{}", version, target))
.expect("failed to parse rust-lang.org doc URL");
let url = Url::from_generic_url(url).expect("failed to convert url::Url to iron::Url");

Self { url }
Expand Down