From c04ea0dc4b0f2c5ddf4c15b796f0439905116a34 Mon Sep 17 00:00:00 2001 From: A Farzat Date: Thu, 5 Mar 2026 19:08:44 +0300 Subject: Gather stylesheet file entries for each chapter This prepares them to be added to their xhtml content. --- src/epub.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/epub.rs') diff --git a/src/epub.rs b/src/epub.rs index 406135b..946c9ee 100644 --- a/src/epub.rs +++ b/src/epub.rs @@ -91,6 +91,11 @@ pub fn create_epub_archive( .iter() .map(|e| (e.url.path(), &e.full_path)) .collect::>(); + // Prepare url to local path mapping to insert related assets based on their URL. + let url_to_file = file_entries + .iter() + .map(|e| (&e.url, e)) + .collect::>(); // Add the rest of the files according to file_entries. let options: FileOptions<()> = @@ -100,7 +105,13 @@ pub fn create_epub_archive( let mut src_file = std::fs::File::open(entry.full_path.to_path(epub_root))?; let mut buffer = Vec::new(); src_file.read_to_end(&mut buffer)?; - if chapters.contains_key(&entry.ourn) { + if let Some(chapter) = chapters.get(&entry.ourn) { + let stylesheet_entries = chapter + .related_assets + .stylesheets + .iter() + .filter_map(|u| url_to_file.get(u)) + .collect::>(); let mut html = String::from_utf8(buffer)?; let chapter_dir = entry.full_path.parent().unwrap_or(RelativePath::new("")); for (url_path, local_path) in &url_path_to_local { -- cgit v1.2.3-70-g09d2