@@ -496,6 +496,11 @@ pub(crate) async fn get_all_platforms(
496496 Extension ( pool) : Extension < Pool > ,
497497 uri : Uri ,
498498) -> AxumResult < AxumResponse > {
499+ let is_crate_root = params
500+ . path
501+ . as_ref ( )
502+ . map ( |path| path == "index.html" )
503+ . unwrap_or ( true ) ;
499504 let req_path: String = params. path . unwrap_or_default ( ) ;
500505 let req_path: Vec < & str > = req_path. split ( '/' ) . collect ( ) ;
501506
@@ -618,7 +623,7 @@ pub(crate) async fn get_all_platforms(
618623 doc_targets,
619624 } ,
620625 inner_path,
621- use_direct_platform_links : true ,
626+ use_direct_platform_links : is_crate_root ,
622627 current_target,
623628 } ;
624629 Ok ( res. into_response ( ) )
@@ -1235,12 +1240,38 @@ mod tests {
12351240
12361241 #[ test]
12371242 fn platform_links_are_direct_and_without_nofollow ( ) {
1243+ fn check_links ( response_text : String , should_contain_redirect : bool ) {
1244+ let platform_links: Vec < ( String , String ) > = kuchikiki:: parse_html ( )
1245+ . one ( response_text)
1246+ . select ( r#"li a"# )
1247+ . expect ( "invalid selector" )
1248+ . map ( |el| {
1249+ let attributes = el. attributes . borrow ( ) ;
1250+ let url = attributes. get ( "href" ) . expect ( "href" ) . to_string ( ) ;
1251+ let rel = attributes. get ( "rel" ) . unwrap_or ( "" ) . to_string ( ) ;
1252+ ( url, rel)
1253+ } )
1254+ . collect ( ) ;
1255+
1256+ assert_eq ! ( platform_links. len( ) , 2 ) ;
1257+
1258+ for ( url, rel) in platform_links {
1259+ assert_eq ! ( url. contains( "/target-redirect/" ) , should_contain_redirect) ;
1260+ if !should_contain_redirect {
1261+ assert_eq ! ( rel, "" ) ;
1262+ } else {
1263+ assert_eq ! ( rel, "nofollow" ) ;
1264+ }
1265+ }
1266+ }
1267+
12381268 wrapper ( |env| {
12391269 env. fake_release ( )
12401270 . name ( "dummy" )
12411271 . version ( "0.4.0" )
12421272 . rustdoc_file ( "dummy/index.html" )
12431273 . rustdoc_file ( "x86_64-pc-windows-msvc/dummy/index.html" )
1274+ . rustdoc_file ( "x86_64-pc-windows-msvc/dummy/struct.A.html" )
12441275 . default_target ( "x86_64-unknown-linux-gnu" )
12451276 . add_target ( "x86_64-pc-windows-msvc" )
12461277 . create ( ) ?;
@@ -1250,25 +1281,14 @@ mod tests {
12501281 . get ( "/-/menus/platforms/dummy/0.4.0/x86_64-pc-windows-msvc" )
12511282 . send ( ) ?;
12521283 assert ! ( response. status( ) . is_success( ) ) ;
1284+ check_links ( response. text ( ) ?, false ) ;
12531285
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- }
1286+ let response = env
1287+ . frontend ( )
1288+ . get ( "/-/menus/platforms/dummy/0.4.0/x86_64-pc-windows-msvc/struct.A.html" )
1289+ . send ( ) ?;
1290+ assert ! ( response. status( ) . is_success( ) ) ;
1291+ check_links ( response. text ( ) ?, true ) ;
12721292
12731293 Ok ( ( ) )
12741294 } ) ;
0 commit comments