Add first attempt to save an epub file

This commit is contained in:
Kenneth Gitere 2020-05-02 19:25:31 +03:00
parent e5a318282d
commit 4e8812c1ee
3 changed files with 658 additions and 57 deletions

699
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -9,6 +9,7 @@ license = "MIT"
[dependencies] [dependencies]
async-std = "1.5.0" async-std = "1.5.0"
epub-builder = "0.4.5"
kuchiki = "0.8.0" kuchiki = "0.8.0"
md5 = "0.7.0" md5 = "0.7.0"
surf = "1.0.3" surf = "1.0.3"

View file

@ -1,6 +1,7 @@
use std::fs::File; use std::fs::File;
use async_std::task; use async_std::task;
use epub_builder::{EpubBuilder, EpubContent, ZipLibrary};
use url::Url; use url::Url;
mod extractor; mod extractor;
@ -24,14 +25,22 @@ fn main() {
.download_images(&Url::parse(urls[5]).unwrap()) .download_images(&Url::parse(urls[5]).unwrap())
.await .await
.expect("Unable to download images"); .expect("Unable to download images");
let mut out_file = File::create("out.html").unwrap(); let mut out_file = File::create("out.epub").unwrap();
let mut html_buf = Vec::new();
extractor extractor
.content .content
.unwrap() .unwrap()
.as_node() .as_node()
.serialize(&mut out_file) .serialize(&mut html_buf)
.expect("Unable to serialize"); .expect("Unable to serialize");
}); let html_buf = std::str::from_utf8(&html_buf).unwrap();
EpubBuilder::new(ZipLibrary::new().unwrap())
.unwrap()
.add_content(EpubContent::new("code.xhtml", html_buf.as_bytes()))
.unwrap()
.generate(&mut out_file)
.unwrap();
})
} }
async fn fetch_url(url: &str) -> String { async fn fetch_url(url: &str) -> String {