mirror of https://github.com/kiwix/libkiwix.git
commit
b641f7b116
10
src/book.cpp
10
src/book.cpp
|
@ -131,6 +131,14 @@ void Book::updateFromXml(const pugi::xml_node& node, const std::string& baseDir)
|
||||||
#undef ATTR
|
#undef ATTR
|
||||||
|
|
||||||
|
|
||||||
|
static std::string fromOpdsDate(const std::string& date)
|
||||||
|
{
|
||||||
|
//The opds date use the standard <YYYY>-<MM>-<DD>T<HH>:<mm>:<SS>Z
|
||||||
|
//and we want <YYYY>-<MM>-<DD>. That's easy, let's take the first 10 char
|
||||||
|
return date.substr(0, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define VALUE(name) node.child(name).child_value()
|
#define VALUE(name) node.child(name).child_value()
|
||||||
void Book::updateFromOpds(const pugi::xml_node& node, const std::string& urlHost)
|
void Book::updateFromOpds(const pugi::xml_node& node, const std::string& urlHost)
|
||||||
{
|
{
|
||||||
|
@ -141,7 +149,7 @@ void Book::updateFromOpds(const pugi::xml_node& node, const std::string& urlHost
|
||||||
m_title = VALUE("title");
|
m_title = VALUE("title");
|
||||||
m_description = VALUE("description");
|
m_description = VALUE("description");
|
||||||
m_language = VALUE("language");
|
m_language = VALUE("language");
|
||||||
m_date = VALUE("updated");
|
m_date = fromOpdsDate(VALUE("updated"));
|
||||||
m_creator = node.child("author").child("name").child_value();
|
m_creator = node.child("author").child("name").child_value();
|
||||||
for(auto linkNode = node.child("link"); linkNode;
|
for(auto linkNode = node.child("link"); linkNode;
|
||||||
linkNode = linkNode.next_sibling("link")) {
|
linkNode = linkNode.next_sibling("link")) {
|
||||||
|
|
|
@ -64,8 +64,6 @@ void LibXMLDumper::handleBook(Book book, pugi::xml_node root_node) {
|
||||||
ADD_ATTR_NOT_EMPTY(entry_node, "creator", book.getCreator());
|
ADD_ATTR_NOT_EMPTY(entry_node, "creator", book.getCreator());
|
||||||
ADD_ATTR_NOT_EMPTY(entry_node, "publisher", book.getPublisher());
|
ADD_ATTR_NOT_EMPTY(entry_node, "publisher", book.getPublisher());
|
||||||
ADD_ATTR_NOT_EMPTY(entry_node, "faviconMimeType", book.getFaviconMimeType());
|
ADD_ATTR_NOT_EMPTY(entry_node, "faviconMimeType", book.getFaviconMimeType());
|
||||||
ADD_ATTR_NOT_EMPTY(entry_node, "language", book.getLanguage());
|
|
||||||
ADD_ATTR_NOT_EMPTY(entry_node, "language", book.getLanguage());
|
|
||||||
if (!book.getFavicon().empty())
|
if (!book.getFavicon().empty())
|
||||||
ADD_ATTRIBUTE(entry_node, "favicon", base64_encode(book.getFavicon()));
|
ADD_ATTRIBUTE(entry_node, "favicon", base64_encode(book.getFavicon()));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -50,6 +50,13 @@ std::string gen_date_str()
|
||||||
return is.str();
|
return is.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string gen_date_from_yyyy_mm_dd(const std::string& date)
|
||||||
|
{
|
||||||
|
std::stringstream is;
|
||||||
|
is << date << "T00:00::00:Z";
|
||||||
|
return is.str();
|
||||||
|
}
|
||||||
|
|
||||||
void OPDSDumper::setOpenSearchInfo(int totalResults, int startIndex, int count)
|
void OPDSDumper::setOpenSearchInfo(int totalResults, int startIndex, int count)
|
||||||
{
|
{
|
||||||
m_totalResults = totalResults;
|
m_totalResults = totalResults;
|
||||||
|
@ -65,7 +72,7 @@ pugi::xml_node OPDSDumper::handleBook(Book book, pugi::xml_node root_node) {
|
||||||
ADD_TEXT_ENTRY(entry_node, "title", book.getTitle());
|
ADD_TEXT_ENTRY(entry_node, "title", book.getTitle());
|
||||||
ADD_TEXT_ENTRY(entry_node, "id", "urn:uuid:"+book.getId());
|
ADD_TEXT_ENTRY(entry_node, "id", "urn:uuid:"+book.getId());
|
||||||
ADD_TEXT_ENTRY(entry_node, "icon", rootLocation + "/meta?name=favicon&content=" + book.getHumanReadableIdFromPath());
|
ADD_TEXT_ENTRY(entry_node, "icon", rootLocation + "/meta?name=favicon&content=" + book.getHumanReadableIdFromPath());
|
||||||
ADD_TEXT_ENTRY(entry_node, "updated", date);
|
ADD_TEXT_ENTRY(entry_node, "updated", gen_date_from_yyyy_mm_dd(book.getDate()));
|
||||||
ADD_TEXT_ENTRY(entry_node, "summary", book.getDescription());
|
ADD_TEXT_ENTRY(entry_node, "summary", book.getDescription());
|
||||||
|
|
||||||
auto content_node = entry_node.append_child("link");
|
auto content_node = entry_node.append_child("link");
|
||||||
|
|
Loading…
Reference in New Issue