Skip to content

Commit

Permalink
doc: Fix resources reading when creating the Doc
Browse files Browse the repository at this point in the history
  • Loading branch information
danigm committed Jun 26, 2023
1 parent 455f07e commit eccf625
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,25 @@ impl<R: Read + Seek> EpubDoc<R> {
let root = xmlutils::XMLReader::parse(container.as_slice())?;
let unique_identifier_id = &root.borrow().get_attr("unique-identifier");

// resources from manifest
// This should be run before everything else, because other functions relies on
// self.resources and should be filled before calling `fill_toc`
let manifest = root
.borrow()
.find("manifest")
.ok_or(DocError::InvalidEpub)?;
for r in &manifest.borrow().children {
let item = r.borrow();
if self.cover_id.is_none() {
if let (Some(id), Some(property)) = (item.get_attr("id"), item.get_attr("properties")) {
if property == "cover-image" {
self.cover_id = Some(id);
}
}
}
let _ = self.insert_resource(&item);
}

// items from spine
let spine = root.borrow().find("spine").ok_or(DocError::InvalidEpub)?;
for r in &spine.borrow().children {
Expand Down Expand Up @@ -652,22 +671,6 @@ impl<R: Read + Seek> EpubDoc<R> {
}
}

// resources from manifest
let manifest = root
.borrow()
.find("manifest")
.ok_or(DocError::InvalidEpub)?;
for r in &manifest.borrow().children {
let item = r.borrow();
if self.cover_id.is_none() {
if let (Some(id), Some(property)) = (item.get_attr("id"), item.get_attr("properties")) {
if property == "cover-image" {
self.cover_id = Some(id);
}
}
}
let _ = self.insert_resource(&item);
}
Ok(())
}

Expand Down

0 comments on commit eccf625

Please sign in to comment.