Files other than .md are now copied to the output dir Fixes #52 + Added max-width in css for images

This commit is contained in:
Mathieu David 2015-09-17 19:45:06 +02:00
parent 5960050676
commit b7bcf2e246
3 changed files with 14 additions and 10 deletions

View File

@ -191,6 +191,10 @@ impl Renderer for HtmlHandlebars {
let mut highlight_js = try!(File::create(book.get_dest().join("highlight.js"))); let mut highlight_js = try!(File::create(book.get_dest().join("highlight.js")));
try!(highlight_js.write_all(&theme.highlight_js)); try!(highlight_js.write_all(&theme.highlight_js));
// Copy all remaining files
try!(utils::copy_files_except_ext(book.get_src(), book.get_dest(), true, &["md"]));
Ok(()) Ok(())
} }
} }

View File

@ -332,6 +332,10 @@ html, body {
text-decoration: underline; text-decoration: underline;
} }
.content img {
max-width: 100%;
}
/* Nav icons */ /* Nav icons */
.nav-chapters { .nav-chapters {
font-size: 40px; font-size: 40px;

View File

@ -137,19 +137,19 @@ pub fn remove_dir_content(dir: &Path) -> Result<(), Box<Error>> {
/// `ext_blacklist` array /// `ext_blacklist` array
pub fn copy_files_except_ext(from: &Path, to: &Path, recursive: bool, ext_blacklist: &[&str]) -> Result<(), Box<Error>> { pub fn copy_files_except_ext(from: &Path, to: &Path, recursive: bool, ext_blacklist: &[&str]) -> Result<(), Box<Error>> {
debug!("[fn] copy_files_except_ext");
// Check that from and to are different // Check that from and to are different
if from == to { return Ok(()) } if from == to { return Ok(()) }
println!("[*] Loop"); debug!("[*] Loop");
for entry in try!(fs::read_dir(from)) { for entry in try!(fs::read_dir(from)) {
let entry = try!(entry); let entry = try!(entry);
println!("[*] {:?}", entry.path()); debug!("[*] {:?}", entry.path());
let metadata = try!(entry.metadata()); let metadata = try!(entry.metadata());
// If the entry is a dir and the recursive option is enabled, call itself // If the entry is a dir and the recursive option is enabled, call itself
if metadata.is_dir() && recursive { if metadata.is_dir() && recursive {
if entry.path() == to.to_path_buf() { continue } if entry.path() == to.to_path_buf() { continue }
println!("[*] is dir"); debug!("[*] is dir");
try!(fs::create_dir(&to.join(entry.file_name()))); try!(fs::create_dir(&to.join(entry.file_name())));
try!(copy_files_except_ext( try!(copy_files_except_ext(
&from.join(entry.file_name()), &from.join(entry.file_name()),
@ -162,9 +162,9 @@ pub fn copy_files_except_ext(from: &Path, to: &Path, recursive: bool, ext_blackl
// Check if it is in the blacklist // Check if it is in the blacklist
if let Some(ext) = entry.path().extension() { if let Some(ext) = entry.path().extension() {
if ext_blacklist.contains(&ext.to_str().unwrap()) { continue } if ext_blacklist.contains(&ext.to_str().unwrap()) { continue }
println!("[*] creating path for file: {:?}", &to.join(entry.path().file_name().expect("a file should have a file name..."))); debug!("[*] creating path for file: {:?}", &to.join(entry.path().file_name().expect("a file should have a file name...")));
//try!(create_path(&to.join(entry.path()))); //try!(create_path(&to.join(entry.path())));
println!("[*] creating file: {:?}", &to.join(entry.path().file_name().expect("a file should have a file name..."))); output!("[*] copying file: {:?}\n to {:?}", entry.path(), &to.join(entry.path().file_name().expect("a file should have a file name...")));
try!(fs::copy(entry.path(), &to.join(entry.path().file_name().expect("a file should have a file name...")))); try!(fs::copy(entry.path(), &to.join(entry.path().file_name().expect("a file should have a file name..."))));
} }
} }
@ -210,10 +210,6 @@ mod tests {
} }
// Check if the correct files where created // Check if the correct files where created
for entry in fs::read_dir(&tmp.path().join("output")).unwrap() {
println!("{:?}", entry.ok().unwrap().path())
}
if !(&tmp.path().join("output/file.txt")).exists() { panic!("output/file.txt should exist") } if !(&tmp.path().join("output/file.txt")).exists() { panic!("output/file.txt should exist") }
if (&tmp.path().join("output/file.md")).exists() { panic!("output/file.md should not exist") } if (&tmp.path().join("output/file.md")).exists() { panic!("output/file.md should not exist") }
if !(&tmp.path().join("output/file.png")).exists() { panic!("output/file.png should exist") } if !(&tmp.path().join("output/file.png")).exists() { panic!("output/file.png should exist") }