Skip to content

Commit 59340b6

Browse files
Don't generate unneeded redirections on platforms links on docs.rs crates pages
1 parent b2c47fa commit 59340b6

File tree

5 files changed

+18
-45
lines changed

5 files changed

+18
-45
lines changed

src/web/build_details.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub(crate) struct BuildDetails {
3131
struct BuildDetailsPage {
3232
metadata: MetaData,
3333
build_details: BuildDetails,
34+
use_direct_platform_links: bool,
3435
}
3536

3637
impl_axum_webpage! {
@@ -91,6 +92,7 @@ pub(crate) async fn build_details_handler(
9192
build_time: row.get("build_time"),
9293
output,
9394
},
95+
use_direct_platform_links: true,
9496
}
9597
.into_response())
9698
}

src/web/builds.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct BuildsPage {
3333
builds: Vec<Build>,
3434
limits: Limits,
3535
canonical_url: CanonicalUrl,
36+
use_direct_platform_links: bool,
3637
}
3738

3839
impl_axum_webpage! {
@@ -78,6 +79,7 @@ pub(crate) async fn build_list_handler(
7879
builds,
7980
limits,
8081
canonical_url: CanonicalUrl::from_path(format!("/crate/{name}/latest/builds")),
82+
use_direct_platform_links: true,
8183
}
8284
.into_response())
8385
}

src/web/crate_details.rs

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,30 +1305,12 @@ mod tests {
13051305
platform_links
13061306
}
13071307

1308-
fn run_check_links(
1309-
env: &TestEnvironment,
1310-
url_start: &str,
1311-
url_end: &str,
1312-
extra: &str,
1313-
should_contain_redirect: bool,
1314-
) {
1315-
run_check_links_redir(
1316-
env,
1317-
url_start,
1318-
url_end,
1319-
extra,
1320-
should_contain_redirect,
1321-
should_contain_redirect,
1322-
)
1323-
}
1324-
13251308
fn run_check_links_redir(
13261309
env: &TestEnvironment,
13271310
url_start: &str,
13281311
url_end: &str,
13291312
extra: &str,
13301313
should_contain_redirect: bool,
1331-
ajax_should_contain_redirect: bool,
13321314
) {
13331315
let response = env
13341316
.frontend()
@@ -1351,18 +1333,8 @@ mod tests {
13511333
.send()
13521334
.unwrap();
13531335
assert!(response.status().is_success());
1354-
let list2 = check_links(response.text().unwrap(), true, ajax_should_contain_redirect);
1355-
if should_contain_redirect == ajax_should_contain_redirect {
1356-
assert_eq!(list1, list2);
1357-
} else {
1358-
// If redirects differ, we only check platform names.
1359-
assert!(
1360-
list1.iter().zip(&list2).all(|(a, b)| a.0 == b.0),
1361-
"{:?} != {:?}",
1362-
list1,
1363-
list2,
1364-
);
1365-
}
1336+
let list2 = check_links(response.text().unwrap(), true, should_contain_redirect);
1337+
assert_eq!(list1, list2);
13661338
}
13671339

13681340
wrapper(|env| {
@@ -1379,28 +1351,21 @@ mod tests {
13791351

13801352
// FIXME: For some reason, there are target-redirects on non-AJAX lists on docs.rs
13811353
// crate pages other than the "default" one.
1382-
run_check_links_redir(env, "/crate/dummy/0.4.0", "/features", "", true, false);
1383-
run_check_links_redir(env, "/crate/dummy/0.4.0", "/builds", "", true, false);
1384-
run_check_links_redir(env, "/crate/dummy/0.4.0", "/source/", "", true, false);
1385-
run_check_links_redir(
1386-
env,
1387-
"/crate/dummy/0.4.0",
1388-
"/source/README.md",
1389-
"",
1390-
true,
1391-
false,
1392-
);
1354+
run_check_links_redir(env, "/crate/dummy/0.4.0", "/features", "", false);
1355+
run_check_links_redir(env, "/crate/dummy/0.4.0", "/builds", "", false);
1356+
run_check_links_redir(env, "/crate/dummy/0.4.0", "/source/", "", false);
1357+
run_check_links_redir(env, "/crate/dummy/0.4.0", "/source/README.md", "", false);
13931358

1394-
run_check_links(env, "/crate/dummy/0.4.0", "", "/", false);
1395-
run_check_links(env, "/dummy/latest", "/dummy", "/", true);
1396-
run_check_links(
1359+
run_check_links_redir(env, "/crate/dummy/0.4.0", "", "/", false);
1360+
run_check_links_redir(env, "/dummy/latest", "/dummy", "/", true);
1361+
run_check_links_redir(
13971362
env,
13981363
"/dummy/0.4.0",
13991364
"/x86_64-pc-windows-msvc/dummy",
14001365
"/",
14011366
true,
14021367
);
1403-
run_check_links(
1368+
run_check_links_redir(
14041369
env,
14051370
"/dummy/0.4.0",
14061371
"/x86_64-pc-windows-msvc/dummy/struct.A.html",

src/web/features.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct FeaturesPage {
2424
default_len: usize,
2525
canonical_url: CanonicalUrl,
2626
is_latest_url: bool,
27+
use_direct_platform_links: bool,
2728
}
2829

2930
impl_axum_webpage! {
@@ -89,6 +90,7 @@ pub(crate) async fn build_features_handler(
8990
default_len,
9091
is_latest_url,
9192
canonical_url: CanonicalUrl::from_path(format!("/crate/{}/latest/features", &name)),
93+
use_direct_platform_links: true,
9294
}
9395
.into_response())
9496
}

src/web/source.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ struct SourcePage {
171171
file_content: Option<String>,
172172
canonical_url: CanonicalUrl,
173173
is_latest_url: bool,
174+
use_direct_platform_links: bool,
174175
}
175176

176177
impl_axum_webpage! {
@@ -312,6 +313,7 @@ pub(crate) async fn source_browser_handler(
312313
file_content,
313314
canonical_url,
314315
is_latest_url,
316+
use_direct_platform_links: true,
315317
}
316318
.into_response())
317319
}

0 commit comments

Comments
 (0)