Add generate-old-style-files option to rustdoc
This commit is contained in:
parent
1ac727772b
commit
270151bffb
10 changed files with 77 additions and 25 deletions
|
@ -33,7 +33,7 @@ use std::default::Default;
|
|||
use std::error;
|
||||
use std::fmt::{self, Display, Formatter, Write as FmtWrite};
|
||||
use std::ffi::OsStr;
|
||||
use std::fs::{self, File};
|
||||
use std::fs::{self, File, OpenOptions};
|
||||
use std::io::prelude::*;
|
||||
use std::io::{self, BufWriter, BufReader};
|
||||
use std::mem;
|
||||
|
@ -136,6 +136,8 @@ struct SharedContext {
|
|||
/// If false, the `select` element to have search filtering by crates on rendered docs
|
||||
/// won't be generated.
|
||||
pub generate_search_filter: bool,
|
||||
/// Option disabled by default to generate files used by RLS and some other tools.
|
||||
pub generate_redirect_pages: bool,
|
||||
}
|
||||
|
||||
impl SharedContext {
|
||||
|
@ -504,6 +506,7 @@ pub fn run(mut krate: clean::Crate,
|
|||
resource_suffix,
|
||||
static_root_path,
|
||||
generate_search_filter,
|
||||
generate_redirect_pages,
|
||||
..
|
||||
} = options;
|
||||
|
||||
|
@ -533,6 +536,7 @@ pub fn run(mut krate: clean::Crate,
|
|||
resource_suffix,
|
||||
static_root_path,
|
||||
generate_search_filter,
|
||||
generate_redirect_pages,
|
||||
};
|
||||
|
||||
// If user passed in `--playground-url` arg, we fill in crate name here
|
||||
|
@ -2229,6 +2233,27 @@ impl Context {
|
|||
if !self.render_redirect_pages {
|
||||
all.append(full_path(self, &item), &item_type);
|
||||
}
|
||||
if self.shared.generate_redirect_pages {
|
||||
// Redirect from a sane URL using the namespace to Rustdoc's
|
||||
// URL for the page.
|
||||
let redir_name = format!("{}.{}.html", name, item_type.name_space());
|
||||
let redir_dst = self.dst.join(redir_name);
|
||||
if let Ok(redirect_out) = OpenOptions::new().create_new(true)
|
||||
.write(true)
|
||||
.open(&redir_dst) {
|
||||
let mut redirect_out = BufWriter::new(redirect_out);
|
||||
try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst);
|
||||
}
|
||||
// If the item is a macro, redirect from the old macro URL (with !)
|
||||
// to the new one (without).
|
||||
if item_type == ItemType::Macro {
|
||||
let redir_name = format!("{}.{}!.html", item_type, name);
|
||||
let redir_dst = self.dst.join(redir_name);
|
||||
let redirect_out = try_err!(File::create(&redir_dst), &redir_dst);
|
||||
let mut redirect_out = BufWriter::new(redirect_out);
|
||||
try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue