Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Reduce HTML output in rustdoc #41384

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/librustdoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ serialize = { path = "../libserialize" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
pulldown-cmark = { version = "0.0.14", default-features = false }
minifier = "0.0.3"

[build-dependencies]
build_helper = { path = "../build_helper" }
Expand Down
16 changes: 13 additions & 3 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ use html::item_type::ItemType;
use html::markdown::{self, Markdown, MarkdownHtml, MarkdownSummaryLine};
use html::{highlight, layout};

use minifier::html::minify;

/// A pair of name and its optional document.
pub type NameDoc = (String, Option<String>);

Expand Down Expand Up @@ -951,13 +953,14 @@ impl<'a> SourceCollector<'a> {
href.push_str(component);
href.push('/');
});
let mut fname = p.file_name().expect("source has no filename")
let mut fname = p.file_name()
.expect("source has no filename")
.to_os_string();
fname.push(".html");
cur.push(&fname);
href.push_str(&fname.to_string_lossy());

let mut w = BufWriter::new(File::create(&cur)?);
let mut w = BufWriter::new(Vec::new());
let title = format!("{} -- source", cur.file_name().unwrap()
.to_string_lossy());
let desc = format!("Source to the Rust file `{}`.", filename);
Expand All @@ -972,6 +975,12 @@ impl<'a> SourceCollector<'a> {
&page, &(""), &Source(contents),
self.scx.css_file_extension.is_some())?;
w.flush()?;
let mut file = File::create(&cur)?;
let content = unsafe {
minify(&String::from_utf8_unchecked(w.into_inner().expect("Couldn't get html content")))
};
file.write(content.as_bytes())?;
file.sync_all()?;
self.scx.local_sources.insert(p, href);
Ok(())
}
Expand Down Expand Up @@ -1362,7 +1371,8 @@ impl Context {
let joint_dst = this.dst.join("index.html");
try_err!(fs::create_dir_all(&this.dst), &this.dst);
let mut dst = try_err!(File::create(&joint_dst), &joint_dst);
try_err!(dst.write_all(&buf), &joint_dst);
let content = unsafe { minify(&String::from_utf8_unchecked(buf)) };
try_err!(dst.write_all(content.as_bytes()), &joint_dst);
}

let m = match item.inner {
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extern crate arena;
extern crate getopts;
extern crate env_logger;
extern crate libc;
extern crate minifier;
extern crate rustc;
extern crate rustc_data_structures;
extern crate rustc_trans;
Expand Down