mirror of
https://github.com/lise-henry/crowbook
synced 2024-09-30 00:43:44 +02:00
Add image support for HtmlDirRenderer
This commit is contained in:
parent
21ec13a79a
commit
a145d78cf5
@ -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
|
||||
|
@ -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));
|
||||
|
@ -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!("<div id = \"cover\">
|
||||
<img class = \"cover\" alt = \"{}\" src = \"{}\" />
|
||||
</div>",
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user