@@ -496,6 +496,7 @@ pub(crate) async fn get_all_platforms(
496
496
Extension ( pool) : Extension < Pool > ,
497
497
uri : Uri ,
498
498
) -> AxumResult < AxumResponse > {
499
+ let is_crate_root = params. path . as_ref ( ) . map ( |path| path == "index.html" ) . unwrap_or ( true ) ;
499
500
let req_path: String = params. path . unwrap_or_default ( ) ;
500
501
let req_path: Vec < & str > = req_path. split ( '/' ) . collect ( ) ;
501
502
@@ -618,7 +619,7 @@ pub(crate) async fn get_all_platforms(
618
619
doc_targets,
619
620
} ,
620
621
inner_path,
621
- use_direct_platform_links : true ,
622
+ use_direct_platform_links : is_crate_root ,
622
623
current_target,
623
624
} ;
624
625
Ok ( res. into_response ( ) )
@@ -1235,12 +1236,38 @@ mod tests {
1235
1236
1236
1237
#[ test]
1237
1238
fn platform_links_are_direct_and_without_nofollow ( ) {
1239
+ fn check_links ( response_text : String , should_contain_redirect : bool ) {
1240
+ let platform_links: Vec < ( String , String ) > = kuchikiki:: parse_html ( )
1241
+ . one ( response_text)
1242
+ . select ( r#"li a"# )
1243
+ . expect ( "invalid selector" )
1244
+ . map ( |el| {
1245
+ let attributes = el. attributes . borrow ( ) ;
1246
+ let url = attributes. get ( "href" ) . expect ( "href" ) . to_string ( ) ;
1247
+ let rel = attributes. get ( "rel" ) . unwrap_or ( "" ) . to_string ( ) ;
1248
+ ( url, rel)
1249
+ } )
1250
+ . collect ( ) ;
1251
+
1252
+ assert_eq ! ( platform_links. len( ) , 2 ) ;
1253
+
1254
+ for ( url, rel) in platform_links {
1255
+ assert_eq ! ( url. contains( "/target-redirect/" ) , should_contain_redirect) ;
1256
+ if !should_contain_redirect {
1257
+ assert_eq ! ( rel, "" ) ;
1258
+ } else {
1259
+ assert_eq ! ( rel, "nofollow" ) ;
1260
+ }
1261
+ }
1262
+ }
1263
+
1238
1264
wrapper ( |env| {
1239
1265
env. fake_release ( )
1240
1266
. name ( "dummy" )
1241
1267
. version ( "0.4.0" )
1242
1268
. rustdoc_file ( "dummy/index.html" )
1243
1269
. rustdoc_file ( "x86_64-pc-windows-msvc/dummy/index.html" )
1270
+ . rustdoc_file ( "x86_64-pc-windows-msvc/dummy/struct.A.html" )
1244
1271
. default_target ( "x86_64-unknown-linux-gnu" )
1245
1272
. add_target ( "x86_64-pc-windows-msvc" )
1246
1273
. create ( ) ?;
@@ -1250,25 +1277,14 @@ mod tests {
1250
1277
. get ( "/-/menus/platforms/dummy/0.4.0/x86_64-pc-windows-msvc" )
1251
1278
. send ( ) ?;
1252
1279
assert ! ( response. status( ) . is_success( ) ) ;
1280
+ check_links ( response. text ( ) ?, false ) ;
1253
1281
1254
- let platform_links: Vec < ( String , String ) > = kuchikiki:: parse_html ( )
1255
- . one ( response. text ( ) ?)
1256
- . select ( r#"li a"# )
1257
- . expect ( "invalid selector" )
1258
- . map ( |el| {
1259
- let attributes = el. attributes . borrow ( ) ;
1260
- let url = attributes. get ( "href" ) . expect ( "href" ) . to_string ( ) ;
1261
- let rel = attributes. get ( "rel" ) . unwrap_or ( "" ) . to_string ( ) ;
1262
- ( url, rel)
1263
- } )
1264
- . collect ( ) ;
1265
-
1266
- assert_eq ! ( platform_links. len( ) , 2 ) ;
1267
-
1268
- for ( url, rel) in platform_links {
1269
- assert ! ( !url. contains( "/target-redirect/" ) ) ;
1270
- assert_eq ! ( rel, "" ) ;
1271
- }
1282
+ let response = env
1283
+ . frontend ( )
1284
+ . get ( "/-/menus/platforms/dummy/0.4.0/x86_64-pc-windows-msvc/struct.A.html" )
1285
+ . send ( ) ?;
1286
+ assert ! ( response. status( ) . is_success( ) ) ;
1287
+ check_links ( response. text ( ) ?, true ) ;
1272
1288
1273
1289
Ok ( ( ) )
1274
1290
} ) ;
0 commit comments