@@ -73,6 +73,18 @@ use minifier;
7373/// A pair of name and its optional document.
7474pub type NameDoc = ( String , Option < String > ) ;
7575
76+ pub struct SlashChecker < ' a > ( pub & ' a str ) ;
77+
78+ impl < ' a > Display for SlashChecker < ' a > {
79+ fn fmt ( & self , f : & mut Formatter ) -> fmt:: Result {
80+ if !self . 0 . ends_with ( "/" ) && !self . 0 . is_empty ( ) {
81+ write ! ( f, "{}/" , self . 0 )
82+ } else {
83+ write ! ( f, "{}" , self . 0 )
84+ }
85+ }
86+ }
87+
7688/// Major driving force in all rustdoc rendering. This contains information
7789/// about where in the tree-like hierarchy rendering is occurring and controls
7890/// how the current page is being rendered.
@@ -1140,7 +1152,8 @@ themePicker.onblur = handleThemeButtonsBlur;
11401152 krates
11411153 . iter( )
11421154 . map( |s| {
1143- format!( "<li><a href=\" {}/index.html\" >{}</li>" , s, s)
1155+ format!( "<li><a href=\" {}index.html\" >{}</li>" ,
1156+ SlashChecker ( s) , s)
11441157 } )
11451158 . collect:: <String >( ) ) ;
11461159 try_err ! ( layout:: render( & mut w, & cx. shared. layout,
@@ -2075,8 +2088,7 @@ impl Context {
20752088 let mut themes = self . shared . themes . clone ( ) ;
20762089 let sidebar = "<p class='location'>Settings</p><div class='sidebar-elems'></div>" ;
20772090 themes. push ( PathBuf :: from ( "settings.css" ) ) ;
2078- let mut layout = self . shared . layout . clone ( ) ;
2079- layout. krate = String :: new ( ) ;
2091+ let layout = self . shared . layout . clone ( ) ;
20802092 try_err ! ( layout:: render( & mut w, & layout,
20812093 & page, & sidebar, & settings,
20822094 self . shared. css_file_extension. is_some( ) ,
@@ -2455,7 +2467,7 @@ impl<'a> fmt::Display for Item<'a> {
24552467
24562468fn item_path ( ty : ItemType , name : & str ) -> String {
24572469 match ty {
2458- ItemType :: Module => format ! ( "{}/ index.html" , name) ,
2470+ ItemType :: Module => format ! ( "{}index.html" , SlashChecker ( name) ) ,
24592471 _ => format ! ( "{}.{}.html" , ty. css_class( ) , name) ,
24602472 }
24612473}
0 commit comments