Skip to content

Commit 5ca7f46

Browse files
jshajyn514
authored andcommitted
Rewrite latest_path logic
1 parent 6e354ec commit 5ca7f46

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/web/rustdoc.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -457,23 +457,27 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
457457
};
458458

459459
// Find the path of the latest version for the `Go to latest` and `Permalink` links
460-
let mut latest_path = if latest_release.build_status {
460+
let target_redirect = if latest_release.build_status {
461461
let target = if target.is_empty() {
462462
&krate.metadata.default_target
463463
} else {
464464
target
465465
};
466-
format!(
467-
"/crate/{}/{}/target-redirect/{}/{}",
468-
name, latest_version, target, inner_path
469-
)
466+
format!("/target-redirect/{}/{}", target, inner_path)
470467
} else {
471-
format!("/crate/{}/{}", name, latest_version)
468+
"".to_string()
472469
};
473-
if let Some(query) = req.url.query() {
474-
latest_path.push('?');
475-
latest_path.push_str(query);
476-
}
470+
471+
let query_string = if let Some(query) = req.url.query() {
472+
format!("?{}", query)
473+
} else {
474+
"".to_string()
475+
};
476+
477+
let latest_path = format!(
478+
"/crate/{}/{}{}{}",
479+
name, latest_version, target_redirect, query_string
480+
);
477481

478482
metrics
479483
.recently_accessed_releases

0 commit comments

Comments
 (0)