aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorA Farzat <a@farzat.xyz>2026-03-04 21:14:32 +0300
committerA Farzat <a@farzat.xyz>2026-03-04 21:14:32 +0300
commita31db5a182c7d45ca6720a99c409b5c35fad69bb (patch)
treec590e42fb84847fd4639124a28174fb9306abb7b /src/main.rs
parentd34403eddc75188b1657a7076442b48da76bb727 (diff)
downloadoreilly-epub-a31db5a182c7d45ca6720a99c409b5c35fad69bb.tar.gz
oreilly-epub-a31db5a182c7d45ca6720a99c409b5c35fad69bb.zip
Convert URLs pointing upstream to local relative
EPUB standard only recognizes relative paths. Fixes image rendering.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 3c5956e..80f81e4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,6 +2,7 @@ mod epub;
mod http_client;
mod models;
+use std::collections::HashMap;
use std::path::Path;
use crate::epub::{create_epub_archive, download_all_files};
@@ -107,6 +108,8 @@ async fn main() -> Result<()> {
println!("Fetching book structure...");
let chapters: Vec<Chapter> = fetch_all_pages(&client, epub_data.chapters.clone()).await?;
+ let chapters: HashMap<String, Chapter> =
+ chapters.into_iter().map(|c| (c.ourn.clone(), c)).collect();
let file_entries: Vec<FileEntry> = fetch_all_pages(&client, epub_data.files.clone()).await?;
let spine_items: Vec<SpineItem> = fetch_all_pages(&client, epub_data.spine.clone()).await?;
let toc_vec: Vec<TocNode> = fetch_direct_array(&client, &epub_data.table_of_contents).await?;
@@ -116,7 +119,7 @@ async fn main() -> Result<()> {
download_all_files(&client, &file_entries, dest_root).await?;
let epub_path = format!("Books/{0}/{0}.epub", args.bookid);
let epub_path = Path::new(&epub_path);
- create_epub_archive(dest_root, &epub_path, &file_entries)?;
+ create_epub_archive(dest_root, epub_path, &file_entries, &chapters)?;
Ok(())
}