Auto merge of #54543 - GuillaumeGomez:top-level-index, r=QuietMisdreavus
Add index page argument @Mark-Simulacrum: I might need some help from you: in bootstrap, I want to add an argument (a new flag added into `rustdoc`) in order to generate the current index directly when `rustdoc` is documenting the `std` lib. However, my change in `bootstrap` didn't do it and I assume it must be moved inside the `Std` struct. But there, I don't see how to pass it to `rustdoc` through `cargo`. Did I miss anything? r? @QuietMisdreavus
This commit is contained in:
commit
e53a5ffd6b
7 changed files with 179 additions and 54 deletions
|
@ -54,6 +54,9 @@ use std::rc::Rc;
|
|||
|
||||
use externalfiles::ExternalHtml;
|
||||
|
||||
use errors;
|
||||
use getopts;
|
||||
|
||||
use serialize::json::{ToJson, Json, as_json};
|
||||
use syntax::ast;
|
||||
use syntax::ext::base::MacroKind;
|
||||
|
@ -106,6 +109,8 @@ struct Context {
|
|||
/// The map used to ensure all generated 'id=' attributes are unique.
|
||||
id_map: Rc<RefCell<IdMap>>,
|
||||
pub shared: Arc<SharedContext>,
|
||||
pub enable_index_page: bool,
|
||||
pub index_page: Option<PathBuf>,
|
||||
}
|
||||
|
||||
struct SharedContext {
|
||||
|
@ -501,7 +506,12 @@ pub fn run(mut krate: clean::Crate,
|
|||
sort_modules_alphabetically: bool,
|
||||
themes: Vec<PathBuf>,
|
||||
enable_minification: bool,
|
||||
id_map: IdMap) -> Result<(), Error> {
|
||||
id_map: IdMap,
|
||||
enable_index_page: bool,
|
||||
index_page: Option<PathBuf>,
|
||||
matches: &getopts::Matches,
|
||||
diag: &errors::Handler,
|
||||
) -> Result<(), Error> {
|
||||
let src_root = match krate.src {
|
||||
FileName::Real(ref p) => match p.parent() {
|
||||
Some(p) => p.to_path_buf(),
|
||||
|
@ -572,6 +582,8 @@ pub fn run(mut krate: clean::Crate,
|
|||
codes: ErrorCodes::from(UnstableFeatures::from_environment().is_nightly_build()),
|
||||
id_map: Rc::new(RefCell::new(id_map)),
|
||||
shared: Arc::new(scx),
|
||||
enable_index_page,
|
||||
index_page,
|
||||
};
|
||||
|
||||
// Crawl the crate to build various caches used for the output
|
||||
|
@ -666,7 +678,7 @@ pub fn run(mut krate: clean::Crate,
|
|||
CACHE_KEY.with(|v| *v.borrow_mut() = cache.clone());
|
||||
CURRENT_LOCATION_KEY.with(|s| s.borrow_mut().clear());
|
||||
|
||||
write_shared(&cx, &krate, &*cache, index, enable_minification)?;
|
||||
write_shared(&cx, &krate, &*cache, index, enable_minification, matches, diag)?;
|
||||
|
||||
// And finally render the whole crate's documentation
|
||||
cx.krate(krate)
|
||||
|
@ -742,11 +754,15 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
|
|||
Json::Object(crate_data))
|
||||
}
|
||||
|
||||
fn write_shared(cx: &Context,
|
||||
krate: &clean::Crate,
|
||||
cache: &Cache,
|
||||
search_index: String,
|
||||
enable_minification: bool) -> Result<(), Error> {
|
||||
fn write_shared(
|
||||
cx: &Context,
|
||||
krate: &clean::Crate,
|
||||
cache: &Cache,
|
||||
search_index: String,
|
||||
enable_minification: bool,
|
||||
matches: &getopts::Matches,
|
||||
diag: &errors::Handler,
|
||||
) -> Result<(), Error> {
|
||||
// Write out the shared files. Note that these are shared among all rustdoc
|
||||
// docs placed in the output directory, so this needs to be a synchronized
|
||||
// operation with respect to all other rustdocs running around.
|
||||
|
@ -902,8 +918,9 @@ themePicker.onblur = handleThemeButtonsBlur;
|
|||
write(cx.dst.join("COPYRIGHT.txt"),
|
||||
include_bytes!("static/COPYRIGHT.txt"))?;
|
||||
|
||||
fn collect(path: &Path, krate: &str, key: &str) -> io::Result<Vec<String>> {
|
||||
fn collect(path: &Path, krate: &str, key: &str) -> io::Result<(Vec<String>, Vec<String>)> {
|
||||
let mut ret = Vec::new();
|
||||
let mut krates = Vec::new();
|
||||
if path.exists() {
|
||||
for line in BufReader::new(File::open(path)?).lines() {
|
||||
let line = line?;
|
||||
|
@ -914,9 +931,13 @@ themePicker.onblur = handleThemeButtonsBlur;
|
|||
continue;
|
||||
}
|
||||
ret.push(line.to_string());
|
||||
krates.push(line[key.len() + 2..].split('"')
|
||||
.next()
|
||||
.map(|s| s.to_owned())
|
||||
.unwrap_or_else(|| String::new()));
|
||||
}
|
||||
}
|
||||
Ok(ret)
|
||||
Ok((ret, krates))
|
||||
}
|
||||
|
||||
fn show_item(item: &IndexItem, krate: &str) -> String {
|
||||
|
@ -931,7 +952,7 @@ themePicker.onblur = handleThemeButtonsBlur;
|
|||
|
||||
let dst = cx.dst.join("aliases.js");
|
||||
{
|
||||
let mut all_aliases = try_err!(collect(&dst, &krate.name, "ALIASES"), &dst);
|
||||
let (mut all_aliases, _) = try_err!(collect(&dst, &krate.name, "ALIASES"), &dst);
|
||||
let mut w = try_err!(File::create(&dst), &dst);
|
||||
let mut output = String::with_capacity(100);
|
||||
for (alias, items) in &cache.aliases {
|
||||
|
@ -955,7 +976,7 @@ themePicker.onblur = handleThemeButtonsBlur;
|
|||
|
||||
// Update the search index
|
||||
let dst = cx.dst.join("search-index.js");
|
||||
let mut all_indexes = try_err!(collect(&dst, &krate.name, "searchIndex"), &dst);
|
||||
let (mut all_indexes, mut krates) = try_err!(collect(&dst, &krate.name, "searchIndex"), &dst);
|
||||
all_indexes.push(search_index);
|
||||
// Sort the indexes by crate so the file will be generated identically even
|
||||
// with rustdoc running in parallel.
|
||||
|
@ -969,6 +990,46 @@ themePicker.onblur = handleThemeButtonsBlur;
|
|||
}
|
||||
try_err!(writeln!(&mut w, "initSearch(searchIndex);"), &dst);
|
||||
|
||||
if cx.enable_index_page == true {
|
||||
if let Some(ref index_page) = cx.index_page {
|
||||
::markdown::render(index_page,
|
||||
cx.dst.clone(),
|
||||
&matches, &(*cx.shared).layout.external_html,
|
||||
!matches.opt_present("markdown-no-toc"),
|
||||
diag);
|
||||
} else {
|
||||
let dst = cx.dst.join("index.html");
|
||||
let mut w = BufWriter::new(try_err!(File::create(&dst), &dst));
|
||||
let page = layout::Page {
|
||||
title: "Index of crates",
|
||||
css_class: "mod",
|
||||
root_path: "./",
|
||||
description: "List of crates",
|
||||
keywords: BASIC_KEYWORDS,
|
||||
resource_suffix: &cx.shared.resource_suffix,
|
||||
};
|
||||
krates.push(krate.name.clone());
|
||||
krates.sort();
|
||||
krates.dedup();
|
||||
|
||||
let content = format!(
|
||||
"<h1 class='fqn'>\
|
||||
<span class='in-band'>List of all crates</span>\
|
||||
</h1><ul class='mod'>{}</ul>",
|
||||
krates
|
||||
.iter()
|
||||
.map(|s| {
|
||||
format!("<li><a href=\"{}/index.html\">{}</li>", s, s)
|
||||
})
|
||||
.collect::<String>());
|
||||
try_err!(layout::render(&mut w, &cx.shared.layout,
|
||||
&page, &(""), &content,
|
||||
cx.shared.css_file_extension.is_some(),
|
||||
&cx.shared.themes), &dst);
|
||||
try_err!(w.flush(), &dst);
|
||||
}
|
||||
}
|
||||
|
||||
// Update the list of all implementors for traits
|
||||
let dst = cx.dst.join("implementors");
|
||||
for (&did, imps) in &cache.implementors {
|
||||
|
@ -1022,7 +1083,8 @@ themePicker.onblur = handleThemeButtonsBlur;
|
|||
remote_item_type.css_class(),
|
||||
remote_path[remote_path.len() - 1]));
|
||||
|
||||
let mut all_implementors = try_err!(collect(&mydst, &krate.name, "implementors"), &mydst);
|
||||
let (mut all_implementors, _) = try_err!(collect(&mydst, &krate.name, "implementors"),
|
||||
&mydst);
|
||||
all_implementors.push(implementors);
|
||||
// Sort the implementors by crate so the file will be generated
|
||||
// identically even with rustdoc running in parallel.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue