diff --git a/src/opds_dumper.cpp b/src/opds_dumper.cpp index af642246c..91bfb7f44 100644 --- a/src/opds_dumper.cpp +++ b/src/opds_dumper.cpp @@ -73,9 +73,6 @@ IllustrationInfo getBookIllustrationInfo(const Book& book) kainjow::mustache::object getSingleBookData(const Book& book) { const auto bookDate = book.getDate() + "T00:00:00Z"; - const MustacheData bookUrl = book.getUrl().empty() - ? MustacheData(false) - : MustacheData(book.getUrl()); return kainjow::mustache::object{ {"id", book.getId()}, {"name", book.getName()}, @@ -92,7 +89,7 @@ kainjow::mustache::object getSingleBookData(const Book& book) {"media_count", to_string(book.getMediaCount())}, {"author_name", book.getCreator()}, {"publisher_name", book.getPublisher()}, - {"url", bookUrl}, + {"url", onlyAsNonEmptyMustacheValue(book.getUrl())}, {"size", to_string(book.getSize())}, {"icons", getBookIllustrationInfo(book)}, }; @@ -194,7 +191,7 @@ string OPDSDumper::dumpOPDSFeed(const std::vector& bookIds, const s {"date", gen_date_str()}, {"root", rootLocation}, {"feed_id", gen_uuid(libraryId + "/catalog/search?"+query)}, - {"filter", query.empty() ? MustacheData(false) : MustacheData(query)}, + {"filter", onlyAsNonEmptyMustacheValue(query)}, {"totalResults", to_string(m_totalResults)}, {"startIndex", to_string(m_startIndex)}, {"itemsPerPage", to_string(m_count)}, @@ -214,7 +211,7 @@ string OPDSDumper::dumpOPDSFeedV2(const std::vector& bookIds, const {"date", gen_date_str()}, {"endpoint_root", endpointRoot}, {"feed_id", gen_uuid(libraryId + endpoint + "?" + query)}, - {"filter", query.empty() ? MustacheData(false) : MustacheData(query)}, + {"filter", onlyAsNonEmptyMustacheValue(query)}, {"query", query.empty() ? "" : "?" + urlEncode(query)}, {"totalResults", to_string(m_totalResults)}, {"startIndex", to_string(m_startIndex)}, diff --git a/src/tools/otherTools.cpp b/src/tools/otherTools.cpp index 1afcc7d7b..ab5bf5874 100644 --- a/src/tools/otherTools.cpp +++ b/src/tools/otherTools.cpp @@ -370,6 +370,13 @@ std::string kiwix::gen_uuid(const std::string& s) return kiwix::to_string(zim::Uuid::generate(s)); } +kainjow::mustache::data kiwix::onlyAsNonEmptyMustacheValue(const std::string& s) +{ + return s.empty() + ? kainjow::mustache::data(false) + : kainjow::mustache::data(s); +} + std::string kiwix::render_template(const std::string& template_str, kainjow::mustache::data data) { kainjow::mustache::mustache tmpl(template_str); diff --git a/src/tools/otherTools.h b/src/tools/otherTools.h index 219332cdb..b1297798e 100644 --- a/src/tools/otherTools.h +++ b/src/tools/otherTools.h @@ -48,6 +48,10 @@ namespace kiwix std::string gen_date_str(); std::string gen_uuid(const std::string& s); + // if s is empty then returns kainjow::mustache::data(false) + // otherwise kainjow::mustache::data(value) + kainjow::mustache::data onlyAsNonEmptyMustacheValue(const std::string& s); + std::string render_template(const std::string& template_str, kainjow::mustache::data data); }