Skip to content

Commit 31a7550

Browse files
committed
Stop editing html files generated by rustdoc
Thanks to --resource-suffix we no longer need to cast dark magic on html files.
1 parent 7c5d978 commit 31a7550

File tree

1 file changed

+6
-43
lines changed

1 file changed

+6
-43
lines changed

src/utils/copy.rs

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,17 @@ fn copy_files_and_handle_html(source: PathBuf,
4848
target: bool)
4949
-> Result<()> {
5050

51+
// FIXME: handle_html is useless since we started using --resource-suffix
52+
// argument with rustdoc
53+
5154
// Make sure destination directory is exists
5255
if !destination.exists() {
5356
try!(fs::create_dir_all(&destination));
5457
}
5558

56-
// Avoid copying duplicated files
57-
let dup_regex = Regex::new(r"(\.lock|\.txt|\.woff|jquery\.js|playpen\.js|main\.js|\.css)$")
59+
// Avoid copying common files
60+
let dup_regex = Regex::new(
61+
r"(\.lock|\.txt|\.woff|\.svg|\.css|main-.*\.css|main-.*\.js|normalize-.*\.js|rustdoc-.*\.css|storage-.*\.js|theme-.*\.js)$")
5862
.unwrap();
5963

6064
for file in try!(source.read_dir()) {
@@ -72,8 +76,6 @@ fn copy_files_and_handle_html(source: PathBuf,
7276
handle_html,
7377
&rustc_version,
7478
target));
75-
} else if handle_html && file.file_name().into_string().unwrap().ends_with(".html") {
76-
try!(copy_html(&file.path(), &destination_full_path, rustc_version, target));
7779
} else if handle_html && dup_regex.is_match(&file.file_name().into_string().unwrap()[..]) {
7880
continue;
7981
} else {
@@ -85,45 +87,6 @@ fn copy_files_and_handle_html(source: PathBuf,
8587
}
8688

8789

88-
fn copy_html(source: &PathBuf,
89-
destination: &PathBuf,
90-
rustc_version: &str,
91-
target: bool)
92-
-> Result<()> {
93-
94-
let source_file = try!(fs::File::open(source));
95-
let mut destination_file = try!(fs::OpenOptions::new()
96-
.write(true)
97-
.create(true)
98-
.open(destination));
99-
100-
let reader = io::BufReader::new(source_file);
101-
102-
// FIXME: We don't need to store common libraries (jquery and normalize) for the each version
103-
// of rustc. I believe storing only one version of this files should work in every
104-
// documentation page.
105-
let replace_regex =
106-
Regex::new(r#"(href|src)="(.*)(main|jquery|rustdoc|playpen|normalize)\.(css|js)""#)
107-
.unwrap();
108-
let replace_str = format!("$1=\"{}../../$2$3-{}.$4\"",
109-
if target { "../" } else { "" },
110-
rustc_version);
111-
112-
for line in reader.lines() {
113-
let mut line = try!(line);
114-
115-
// replace css links
116-
line = replace_regex.replace_all(&line[..], &replace_str[..]).into_owned();
117-
118-
try!(destination_file.write(line.as_bytes()));
119-
// need to write consumed newline
120-
try!(destination_file.write(&['\n' as u8]));
121-
}
122-
123-
Ok(())
124-
}
125-
126-
12790

12891
#[cfg(test)]
12992
mod test {

0 commit comments

Comments
 (0)