diff --git a/src/lib/bookoptions.rs b/src/lib/bookoptions.rs index ec428df..1dae4f3 100644 --- a/src/lib/bookoptions.rs +++ b/src/lib/bookoptions.rs @@ -25,7 +25,7 @@ output.odt:path # Output file name for ODT rendering # Resources option resources.base_path:path # Path where to find resources (in the source tree). By default, links and images are relative to the Markdown file. If this is set, it will be to this path. resources.base_path.links:path # Set base path but only for links. Useless if resources.base_path is set. -resources.base_path.images:path # Set base path but only for images. Useless if resources.base_path is set. +resources.base_path.images:path:. # Set base path but only for images. Useless if resources.base_path is set. resources.base_path.files:path:. # Set base path but only for additional files. Useless if resources.base_path is set. resources.out_path:path:data # Paths where additional resources should be copied in the EPUB file or HTML directory resources.files:str # Whitespace-separated list of files to embed in e.g. EPUB file diff --git a/src/lib/epub.rs b/src/lib/epub.rs index 7ccc0e0..13cdba0 100644 --- a/src/lib/epub.rs +++ b/src/lib/epub.rs @@ -125,8 +125,9 @@ impl<'a> EpubRenderer<'a> { } // Write all images (including cover) + let images_path = PathBuf::from(&self.book.options.get_path("resources.base_path.images").unwrap()); for (source, dest) in self.html.handler.images_mapping() { - let mut f = try!(File::open(self.book.root.join(source)).map_err(|_| Error::FileNotFound(source.to_owned()))); + let mut f = try!(File::open(images_path.join(source)).map_err(|_| Error::FileNotFound(source.to_owned()))); let mut content = vec!(); try!(f.read_to_end(&mut content).map_err(|e| Error::Render(format!("error while reading image file: {}", e)))); try!(zipper.write(dest, &content, true)); diff --git a/src/lib/html_dir.rs b/src/lib/html_dir.rs index e53122e..8db4e77 100644 --- a/src/lib/html_dir.rs +++ b/src/lib/html_dir.rs @@ -11,6 +11,7 @@ use std::fs; use std::fs::File; use std::path::Path; use std::path::PathBuf; +use std::borrow::Cow; /// Multiple files HTML renderer /// @@ -56,9 +57,20 @@ impl<'a> HtmlDirRenderer<'a> { .create(&dest_path) .map_err(|e| Error::Render(format!("could not create HTML directory {}:{}", &dest_path, e)))); + // Write CSS try!(self.write_css()); + // Write index.html and chapter_xxx.html try!(self.write_html()); + // Write all images (including cover) + let images_path = PathBuf::from(&self.book.options.get_path("resources.base_path.images").unwrap()); + for (source, dest) in self.html.handler.images_mapping() { + let mut f = try!(File::open(images_path.join(source)).map_err(|_| Error::FileNotFound(source.to_owned()))); + let mut content = vec!(); + try!(f.read_to_end(&mut content).map_err(|e| Error::Render(format!("error while reading image file {}: {}", source, e)))); + try!(self.write_file(dest, &content)); + } + Ok(()) } @@ -102,9 +114,18 @@ impl<'a> HtmlDirRenderer<'a> { try!(self.write_file(&filenamer(i), &res)); } + let content = if let Ok(cover) = self.book.options.get_path("cover") { + format!("
+ \"{}\" +
", + self.book.options.get_str("title").unwrap(), + self.html.handler.map_image(Cow::Owned(cover)).as_ref()) + } else { + String::new() + }; // Render index.html and write it too let data = self.book.get_mapbuilder("none") - .insert_str("content", "") + .insert_str("content", content) .insert_str("toc", toc.clone()) .insert_bool(self.book.options.get_str("lang").unwrap(), true) .build();