mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2025-12-18 07:07:41 +03:00
Refactor TOC parsing logic to streamline cover image and NCX item retrieval
This commit is contained in:
parent
496c20cba0
commit
6750380400
@ -70,30 +70,13 @@ bool Epub::parseContentOpf(const std::string& contentOpfFilePath) {
|
||||
// Grab data from opfParser into epub
|
||||
title = opfParser.title;
|
||||
if (!opfParser.coverItemId.empty() && opfParser.items.count(opfParser.coverItemId) > 0) {
|
||||
coverImageItem = opfParser.items.at(opfParser.coverItemId);
|
||||
}
|
||||
constexpr const char* NCX_MEDIA_TYPE = "application/x-dtbncx+xml";
|
||||
|
||||
for (const auto& [id, manifestItem] : opfParser.items) {
|
||||
(void)id;
|
||||
if (manifestItem.mediaType == NCX_MEDIA_TYPE) {
|
||||
tocNcxItem = manifestItem.href;
|
||||
break;
|
||||
}
|
||||
coverImageItem = opfParser.items.at(opfParser.coverItemId).href;
|
||||
}
|
||||
|
||||
if (tocNcxItem.empty() && !opfParser.tocNcxPath.empty()) {
|
||||
if (!opfParser.tocNcxPath.empty()) {
|
||||
tocNcxItem = opfParser.tocNcxPath;
|
||||
}
|
||||
|
||||
if (tocNcxItem.empty()) {
|
||||
if (opfParser.items.count("ncx")) {
|
||||
tocNcxItem = opfParser.items.at("ncx").href;
|
||||
} else if (opfParser.items.count("ncxtoc")) {
|
||||
tocNcxItem = opfParser.items.at("ncxtoc").href;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& spineRef : opfParser.spineRefs) {
|
||||
if (opfParser.items.count(spineRef)) {
|
||||
spine.emplace_back(spineRef, opfParser.items.at(spineRef).href);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user