@@ -33,7 +33,7 @@ use std::default::Default;
33
33
use std:: error;
34
34
use std:: fmt:: { self , Display , Formatter , Write as FmtWrite } ;
35
35
use std:: ffi:: OsStr ;
36
- use std:: fs:: { self , File } ;
36
+ use std:: fs:: { self , File , OpenOptions } ;
37
37
use std:: io:: prelude:: * ;
38
38
use std:: io:: { self , BufWriter , BufReader } ;
39
39
use std:: mem;
@@ -136,6 +136,8 @@ struct SharedContext {
136
136
/// If false, the `select` element to have search filtering by crates on rendered docs
137
137
/// won't be generated.
138
138
pub generate_search_filter : bool ,
139
+ /// Option disabled by default to generate files used by RLS and some other tools.
140
+ pub generate_redirect_pages : bool ,
139
141
}
140
142
141
143
impl SharedContext {
@@ -504,6 +506,7 @@ pub fn run(mut krate: clean::Crate,
504
506
resource_suffix,
505
507
static_root_path,
506
508
generate_search_filter,
509
+ generate_redirect_pages,
507
510
..
508
511
} = options;
509
512
@@ -533,6 +536,7 @@ pub fn run(mut krate: clean::Crate,
533
536
resource_suffix,
534
537
static_root_path,
535
538
generate_search_filter,
539
+ generate_redirect_pages,
536
540
} ;
537
541
538
542
// If user passed in `--playground-url` arg, we fill in crate name here
@@ -2229,6 +2233,27 @@ impl Context {
2229
2233
if !self . render_redirect_pages {
2230
2234
all. append ( full_path ( self , & item) , & item_type) ;
2231
2235
}
2236
+ if self . shared . generate_redirect_pages {
2237
+ // Redirect from a sane URL using the namespace to Rustdoc's
2238
+ // URL for the page.
2239
+ let redir_name = format ! ( "{}.{}.html" , name, item_type. name_space( ) ) ;
2240
+ let redir_dst = self . dst . join ( redir_name) ;
2241
+ if let Ok ( redirect_out) = OpenOptions :: new ( ) . create_new ( true )
2242
+ . write ( true )
2243
+ . open ( & redir_dst) {
2244
+ let mut redirect_out = BufWriter :: new ( redirect_out) ;
2245
+ try_err ! ( layout:: redirect( & mut redirect_out, file_name) , & redir_dst) ;
2246
+ }
2247
+ // If the item is a macro, redirect from the old macro URL (with !)
2248
+ // to the new one (without).
2249
+ if item_type == ItemType :: Macro {
2250
+ let redir_name = format ! ( "{}.{}!.html" , item_type, name) ;
2251
+ let redir_dst = self . dst . join ( redir_name) ;
2252
+ let redirect_out = try_err ! ( File :: create( & redir_dst) , & redir_dst) ;
2253
+ let mut redirect_out = BufWriter :: new ( redirect_out) ;
2254
+ try_err ! ( layout:: redirect( & mut redirect_out, file_name) , & redir_dst) ;
2255
+ }
2256
+ }
2232
2257
}
2233
2258
}
2234
2259
Ok ( ( ) )
0 commit comments