From f1873876b2a4675369c0e044e5924542a39ac406 Mon Sep 17 00:00:00 2001 From: Nikhil Tanwar <2002nikhiltanwar@gmail.com> Date: Fri, 3 Mar 2023 00:30:58 +0530 Subject: [PATCH 01/14] Extract LibraryDumper from OPDSDumper This change creates a new common class for dumping the library into various formats: LibraryDumper --- include/library_dumper.h | 91 +++++++++++++++++++++++++++++ include/opds_dumper.h | 38 +----------- src/library_dumper.cpp | 121 +++++++++++++++++++++++++++++++++++++++ src/meson.build | 1 + src/opds_dumper.cpp | 94 ++---------------------------- 5 files changed, 220 insertions(+), 125 deletions(-) create mode 100644 include/library_dumper.h create mode 100644 src/library_dumper.cpp diff --git a/include/library_dumper.h b/include/library_dumper.h new file mode 100644 index 000000000..3438ef711 --- /dev/null +++ b/include/library_dumper.h @@ -0,0 +1,91 @@ +/* + * Copyright 2023 Nikhil Tanwar <2002nikhiltanwar@gmail.com> + * Copyright 2017 Matthieu Gautier + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#ifndef KIWIX_LIBRARY_DUMPER_H +#define KIWIX_LIBRARY_DUMPER_H + +#include + + +#include "library.h" +#include "name_mapper.h" +#include + +namespace kiwix +{ + +/** + * A base class to dump Library in various formats. + * + */ +class LibraryDumper +{ + public: + LibraryDumper(const Library* library, const NameMapper* NameMapper); + ~LibraryDumper(); + + void setLibraryId(const std::string& id) { this->libraryId = id;} + + /** + * Set the root location used when generating url. + * + * @param rootLocation the root location to use. + */ + void setRootLocation(const std::string& rootLocation) { this->rootLocation = rootLocation; } + + /** + * Set some informations about the search results. + * + * @param totalResult the total number of results of the search. + * @param startIndex the start index of the result. + * @param count the number of result of the current set (or page). + */ + void setOpenSearchInfo(int totalResult, int startIndex, int count); + + /** + * Sets user default language + * + * @param userLang the user language to be set + */ + void setUserLanguage(std::string userLang) { this->m_userLang = userLang; } + + /** + * Get the data of categories + */ + kainjow::mustache::list getCategoryData() const; + + /** + * Get the data of languages + */ + kainjow::mustache::list getLanguageData() const; + + protected: + const kiwix::Library* const library; + const kiwix::NameMapper* const nameMapper; + std::string libraryId; + std::string rootLocation; + std::string m_userLang; + int m_totalResults; + int m_startIndex; + int m_count; +}; +} + +#endif // KIWIX_LIBRARY_DUMPER_H diff --git a/include/opds_dumper.h b/include/opds_dumper.h index cb6566f4f..c2f5ff182 100644 --- a/include/opds_dumper.h +++ b/include/opds_dumper.h @@ -28,6 +28,7 @@ #include "library.h" #include "name_mapper.h" +#include "library_dumper.h" using namespace std; @@ -38,11 +39,10 @@ namespace kiwix * A tool to dump a `Library` into a opds stream. * */ -class OPDSDumper +class OPDSDumper : public LibraryDumper { public: - OPDSDumper() = default; - OPDSDumper(Library* library, NameMapper* NameMapper); + OPDSDumper(const Library* library, const NameMapper* NameMapper); ~OPDSDumper(); /** @@ -85,38 +85,6 @@ class OPDSDumper * @return The OPDS feed. */ std::string languagesOPDSFeed() const; - - /** - * Set the id of the library. - * - * @param id the id to use. - */ - void setLibraryId(const std::string& id) { this->libraryId = id;} - - /** - * Set the root location used when generating url. - * - * @param rootLocation the root location to use. - */ - void setRootLocation(const std::string& rootLocation) { this->rootLocation = rootLocation; } - - /** - * Set some informations about the search results. - * - * @param totalResult the total number of results of the search. - * @param startIndex the start index of the result. - * @param count the number of result of the current set (or page). - */ - void setOpenSearchInfo(int totalResult, int startIndex, int count); - - protected: - kiwix::Library* library; - kiwix::NameMapper* nameMapper; - std::string libraryId; - std::string rootLocation; - int m_totalResults; - int m_startIndex; - int m_count; }; } diff --git a/src/library_dumper.cpp b/src/library_dumper.cpp new file mode 100644 index 000000000..81880db3b --- /dev/null +++ b/src/library_dumper.cpp @@ -0,0 +1,121 @@ +#include "library_dumper.h" +#include "tools/stringTools.h" +#include "tools/otherTools.h" +#include "tools.h" +#include "tools/regexTools.h" + +namespace kiwix +{ +/* Constructor */ +LibraryDumper::LibraryDumper(const Library* library, const NameMapper* nameMapper) + : library(library), + nameMapper(nameMapper) +{ +} +/* Destructor */ +LibraryDumper::~LibraryDumper() +{ +} + +void LibraryDumper::setOpenSearchInfo(int totalResults, int startIndex, int count) +{ + m_totalResults = totalResults; + m_startIndex = startIndex, + m_count = count; +} + +namespace { + +std::map iso639_3 = { + {"atj", "atikamekw"}, + {"azb", "آذربایجان دیلی"}, + {"bcl", "central bikol"}, + {"bgs", "tagabawa"}, + {"bxr", "буряад хэлэн"}, + {"cbk", "chavacano"}, + {"cdo", "閩東語"}, + {"dag", "Dagbani"}, + {"diq", "dimli"}, + {"dty", "डोटेली"}, + {"eml", "emiliân-rumagnōl"}, + {"fbs", "српскохрватски"}, + {"hbs", "srpskohrvatski"}, + {"ido", "ido"}, + {"kbp", "kabɩyɛ"}, + {"kld", "Gamilaraay"}, + {"lbe", "лакку маз"}, + {"lbj", "ལ་དྭགས་སྐད་"}, + {"map", "Austronesian"}, + {"mhr", "марий йылме"}, + {"mnw", "ဘာသာမန်"}, + {"myn", "mayan"}, + {"nah", "nahuatl"}, + {"nai", "north American Indian"}, + {"nds", "plattdütsch"}, + {"nrm", "bhasa narom"}, + {"olo", "livvi"}, + {"pih", "Pitcairn-Norfolk"}, + {"pnb", "Western Panjabi"}, + {"rmr", "Caló"}, + {"rmy", "romani shib"}, + {"roa", "romance languages"}, + {"twi", "twi"}, +}; + +std::once_flag fillLanguagesFlag; + +void fillLanguagesMap() +{ + for (auto icuLangPtr = icu::Locale::getISOLanguages(); *icuLangPtr != NULL; ++icuLangPtr) { + const ICULanguageInfo lang(*icuLangPtr); + iso639_3.insert({lang.iso3Code(), lang.selfName()}); + } +} + +std::string getLanguageSelfName(const std::string& lang) { + const auto itr = iso639_3.find(lang); + if (itr != iso639_3.end()) { + return itr->second; + } + return lang; +}; + +} // unnamed namespace + +kainjow::mustache::list LibraryDumper::getCategoryData() const +{ + const auto now = gen_date_str(); + kainjow::mustache::list categoryData; + for ( const auto& category : library->getBooksCategories() ) { + const auto urlencodedCategoryName = urlEncode(category); + categoryData.push_back(kainjow::mustache::object{ + {"name", category}, + {"urlencoded_name", urlencodedCategoryName}, + {"updated", now}, + {"id", gen_uuid(libraryId + "/categories/" + urlencodedCategoryName)} + }); + } + return categoryData; +} + +kainjow::mustache::list LibraryDumper::getLanguageData() const +{ + const auto now = gen_date_str(); + kainjow::mustache::list languageData; + std::call_once(fillLanguagesFlag, fillLanguagesMap); + for ( const auto& langAndBookCount : library->getBooksLanguagesWithCounts() ) { + const std::string languageCode = langAndBookCount.first; + const int bookCount = langAndBookCount.second; + const auto languageSelfName = getLanguageSelfName(languageCode); + languageData.push_back(kainjow::mustache::object{ + {"lang_code", languageCode}, + {"lang_self_name", languageSelfName}, + {"book_count", to_string(bookCount)}, + {"updated", now}, + {"id", gen_uuid(libraryId + "/languages/" + languageCode)} + }); + } + return languageData; +} + +} // namespace kiwix diff --git a/src/meson.build b/src/meson.build index 3c486fb18..3bbb24f98 100644 --- a/src/meson.build +++ b/src/meson.build @@ -5,6 +5,7 @@ kiwix_sources = [ 'manager.cpp', 'libxml_dumper.cpp', 'opds_dumper.cpp', + 'library_dumper.cpp', 'downloader.cpp', 'server.cpp', 'search_renderer.cpp', diff --git a/src/opds_dumper.cpp b/src/opds_dumper.cpp index 1104029ac..a8b1be9ed 100644 --- a/src/opds_dumper.cpp +++ b/src/opds_dumper.cpp @@ -30,9 +30,8 @@ namespace kiwix { /* Constructor */ -OPDSDumper::OPDSDumper(Library* library, NameMapper* nameMapper) - : library(library), - nameMapper(nameMapper) +OPDSDumper::OPDSDumper(const Library* library, const NameMapper* nameMapper) + : LibraryDumper(library, nameMapper) { } /* Destructor */ @@ -40,13 +39,6 @@ OPDSDumper::~OPDSDumper() { } -void OPDSDumper::setOpenSearchInfo(int totalResults, int startIndex, int count) -{ - m_totalResults = totalResults; - m_startIndex = startIndex, - m_count = count; -} - namespace { @@ -133,60 +125,6 @@ BooksData getBooksData(const Library* library, const NameMapper* nameMapper, con return booksData; } -std::map iso639_3 = { - {"atj", "atikamekw"}, - {"azb", "آذربایجان دیلی"}, - {"bcl", "central bikol"}, - {"bgs", "tagabawa"}, - {"bxr", "буряад хэлэн"}, - {"cbk", "chavacano"}, - {"cdo", "閩東語"}, - {"dag", "Dagbani"}, - {"diq", "dimli"}, - {"dty", "डोटेली"}, - {"eml", "emiliân-rumagnōl"}, - {"fbs", "српскохрватски"}, - {"hbs", "srpskohrvatski"}, - {"ido", "ido"}, - {"kbp", "kabɩyɛ"}, - {"kld", "Gamilaraay"}, - {"lbe", "лакку маз"}, - {"lbj", "ལ་དྭགས་སྐད་"}, - {"map", "Austronesian"}, - {"mhr", "марий йылме"}, - {"mnw", "ဘာသာမန်"}, - {"myn", "mayan"}, - {"nah", "nahuatl"}, - {"nai", "north American Indian"}, - {"nds", "plattdütsch"}, - {"nrm", "bhasa narom"}, - {"olo", "livvi"}, - {"pih", "Pitcairn-Norfolk"}, - {"pnb", "Western Panjabi"}, - {"rmr", "Caló"}, - {"rmy", "romani shib"}, - {"roa", "romance languages"}, - {"twi", "twi"}, -}; - -std::once_flag fillLanguagesFlag; - -void fillLanguagesMap() -{ - for (auto icuLangPtr = icu::Locale::getISOLanguages(); *icuLangPtr != NULL; ++icuLangPtr) { - const ICULanguageInfo lang(*icuLangPtr); - iso639_3.insert({lang.iso3Code(), lang.selfName()}); - } -} - -std::string getLanguageSelfName(const std::string& lang) { - const auto itr = iso639_3.find(lang); - if (itr != iso639_3.end()) { - return itr->second; - } - return lang; -}; - } // unnamed namespace string OPDSDumper::dumpOPDSFeed(const std::vector& bookIds, const std::string& query) const @@ -240,17 +178,7 @@ std::string OPDSDumper::dumpOPDSCompleteEntry(const std::string& bookId) const std::string OPDSDumper::categoriesOPDSFeed() const { const auto now = gen_date_str(); - kainjow::mustache::list categoryData; - for ( const auto& category : library->getBooksCategories() ) { - const auto urlencodedCategoryName = urlEncode(category); - categoryData.push_back(kainjow::mustache::object{ - {"name", category}, - {"urlencoded_name", urlencodedCategoryName}, - {"updated", now}, - {"id", gen_uuid(libraryId + "/categories/" + urlencodedCategoryName)} - }); - } - + kainjow::mustache::list categoryData = getCategoryData(); return render_template( RESOURCE::templates::catalog_v2_categories_xml, kainjow::mustache::object{ @@ -265,21 +193,7 @@ std::string OPDSDumper::categoriesOPDSFeed() const std::string OPDSDumper::languagesOPDSFeed() const { const auto now = gen_date_str(); - kainjow::mustache::list languageData; - std::call_once(fillLanguagesFlag, fillLanguagesMap); - for ( const auto& langAndBookCount : library->getBooksLanguagesWithCounts() ) { - const std::string languageCode = langAndBookCount.first; - const int bookCount = langAndBookCount.second; - const auto languageSelfName = getLanguageSelfName(languageCode); - languageData.push_back(kainjow::mustache::object{ - {"lang_code", languageCode}, - {"lang_self_name", languageSelfName}, - {"book_count", to_string(bookCount)}, - {"updated", now}, - {"id", gen_uuid(libraryId + "/languages/" + languageCode)} - }); - } - + kainjow::mustache::list languageData = getLanguageData(); return render_template( RESOURCE::templates::catalog_v2_languages_xml, kainjow::mustache::object{ From d8656ec149d7e8de0c58017cb7e88cf3c04207e4 Mon Sep 17 00:00:00 2001 From: Nikhil Tanwar <2002nikhiltanwar@gmail.com> Date: Fri, 3 Mar 2023 00:40:04 +0530 Subject: [PATCH 02/14] Introduce HTMLDumper HTMLDumper class will be used to dump library in HTML format. It inherits from LibraryDumper --- include/html_dumper.h | 50 ++++++++++++++++++++++++ src/html_dumper.cpp | 37 ++++++++++++++++++ src/meson.build | 1 + src/server/internalServer.cpp | 1 + static/resources_list.txt | 1 + static/templates/no_js_library_page.html | 40 +++++++++++++++++++ 6 files changed, 130 insertions(+) create mode 100644 include/html_dumper.h create mode 100644 src/html_dumper.cpp create mode 100644 static/templates/no_js_library_page.html diff --git a/include/html_dumper.h b/include/html_dumper.h new file mode 100644 index 000000000..fd09659db --- /dev/null +++ b/include/html_dumper.h @@ -0,0 +1,50 @@ +/* + * Copyright 2023 Nikhil Tanwar <2002nikhiltanwar@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#ifndef KIWIX_HTML_DUMPER_H +#define KIWIX_HTML_DUMPER_H + +#include + +#include "library_dumper.h" + +namespace kiwix +{ + +/** + * A class to dump Library in HTML format. + */ +class HTMLDumper : public LibraryDumper +{ + public: + HTMLDumper(const Library* library, const NameMapper* NameMapper); + ~HTMLDumper(); + + + /** + * Dump library in HTML + * + * @return HTML content + */ + std::string dumpPlainHTML() const; +}; + +} + +#endif // KIWIX_HTML_DUMPER_H diff --git a/src/html_dumper.cpp b/src/html_dumper.cpp new file mode 100644 index 000000000..919e4bcea --- /dev/null +++ b/src/html_dumper.cpp @@ -0,0 +1,37 @@ +#include "html_dumper.h" +#include "libkiwix-resources.h" +#include "tools/otherTools.h" + +namespace kiwix +{ + +/* Constructor */ +HTMLDumper::HTMLDumper(const Library* library, const NameMapper* nameMapper) + : LibraryDumper(library, nameMapper) +{ +} +/* Destructor */ +HTMLDumper::~HTMLDumper() +{ +} + +std::string HTMLDumper::dumpPlainHTML() const +{ + kainjow::mustache::list booksData; + for ( const auto& bookId : library->getBooksIds() ) { + const auto bookEx = library->getBookById(bookId); + const auto bookName = bookEx.getName(); + booksData.push_back(kainjow::mustache::object{ + {"name", bookName} + }); + } + + return render_template( + RESOURCE::templates::no_js_library_page_html, + kainjow::mustache::object{ + {"books", booksData } + } + ); +} + +} // namespace kiwix diff --git a/src/meson.build b/src/meson.build index 3bbb24f98..21486bc4e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -5,6 +5,7 @@ kiwix_sources = [ 'manager.cpp', 'libxml_dumper.cpp', 'opds_dumper.cpp', + 'html_dumper.cpp', 'library_dumper.cpp', 'downloader.cpp', 'server.cpp', diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index 8db0f81f3..b787cb03f 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -53,6 +53,7 @@ extern "C" { #include "name_mapper.h" #include "search_renderer.h" #include "opds_dumper.h" +#include "html_dumper.h" #include "i18n.h" #include diff --git a/static/resources_list.txt b/static/resources_list.txt index 69f8bf961..516c8bfc6 100644 --- a/static/resources_list.txt +++ b/static/resources_list.txt @@ -37,6 +37,7 @@ templates/catalog_v2_categories.xml templates/catalog_v2_languages.xml templates/url_of_search_results_css templates/viewer_settings.js +templates/no_js_library_page.html opensearchdescription.xml ft_opensearchdescription.xml catalog_v2_searchdescription.xml diff --git a/static/templates/no_js_library_page.html b/static/templates/no_js_library_page.html new file mode 100644 index 000000000..0281d85ba --- /dev/null +++ b/static/templates/no_js_library_page.html @@ -0,0 +1,40 @@ + + + + + + + Welcome to Kiwix Server + + + + + + + + + + + + + + VERY REAL TEST :)))))))) + {{#books}} +
{{name}}
+ {{/books}} + + \ No newline at end of file From dca47d35f76f648a535ae597924ae4552e4e3cca Mon Sep 17 00:00:00 2001 From: Nikhil Tanwar <2002nikhiltanwar@gmail.com> Date: Mon, 13 Feb 2023 03:21:56 +0530 Subject: [PATCH 03/14] Introduce /nojs endpoint Adds /nojs endpoint for fallback. Currently, it serves an HTML with book names in library --- src/server/internalServer.cpp | 16 ++++++++++++++++ src/server/internalServer.h | 1 + 2 files changed, 17 insertions(+) diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index b787cb03f..a0236f3e6 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -628,6 +628,9 @@ std::unique_ptr InternalServer::handle_request(const RequestContext& r if (isEndpointUrl(url, "search")) return handle_search(request); + if (isEndpointUrl(url, "nojs")) + return handle_no_js(request); + if (isEndpointUrl(url, "suggest")) return handle_suggest(request); @@ -756,6 +759,19 @@ std::unique_ptr InternalServer::handle_viewer_settings(const RequestCo return ContentResponse::build(*this, RESOURCE::templates::viewer_settings_js, data, "application/javascript; charset=utf-8"); } +std::unique_ptr InternalServer::handle_no_js(const RequestContext& request) +{ + HTMLDumper htmlDumper(mp_library, mp_nameMapper); + htmlDumper.setRootLocation(m_root); + htmlDumper.setLibraryId(getLibraryId()); + return ContentResponse::build( + *this, + htmlDumper.dumpPlainHTML(), + "text/html; charset=utf-8" + ); +} + + namespace { diff --git a/src/server/internalServer.h b/src/server/internalServer.h index b852afa52..a9e0070c8 100644 --- a/src/server/internalServer.h +++ b/src/server/internalServer.h @@ -131,6 +131,7 @@ class InternalServer { std::unique_ptr handle_catalog_v2_entries(const RequestContext& request, bool partial); std::unique_ptr handle_catalog_v2_complete_entry(const RequestContext& request, const std::string& entryId); std::unique_ptr handle_catalog_v2_categories(const RequestContext& request); + std::unique_ptr handle_no_js(const RequestContext& request); std::unique_ptr handle_catalog_v2_languages(const RequestContext& request); std::unique_ptr handle_catalog_v2_illustration(const RequestContext& request); std::unique_ptr handle_search(const RequestContext& request); From 6071b98fb730e6f52a59e3550535803a67b5f85d Mon Sep 17 00:00:00 2001 From: Nikhil Tanwar <2002nikhiltanwar@gmail.com> Date: Mon, 13 Feb 2023 04:35:53 +0530 Subject: [PATCH 04/14] Import book tiles Tries to copy the same design of tiles as main page with javascript enabled --- src/html_dumper.cpp | 14 ++++++++-- static/templates/no_js_library_page.html | 35 +++++++++++++++++++++--- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/html_dumper.cpp b/src/html_dumper.cpp index 919e4bcea..9122a723a 100644 --- a/src/html_dumper.cpp +++ b/src/html_dumper.cpp @@ -19,16 +19,24 @@ std::string HTMLDumper::dumpPlainHTML() const { kainjow::mustache::list booksData; for ( const auto& bookId : library->getBooksIds() ) { - const auto bookEx = library->getBookById(bookId); - const auto bookName = bookEx.getName(); + const auto bookObj = library->getBookById(bookId); + const auto bookTitle = bookObj.getTitle(); + const auto bookDescription = bookObj.getDescription(); + const auto langCode = bookObj.getCommaSeparatedLanguages(); + const auto bookIconUrl = rootLocation + "/catalog/v2/illustration/" + bookId + "/?size=48"; + std::string faviconAttr = "style=background-image:url(" + bookIconUrl + ")"; booksData.push_back(kainjow::mustache::object{ - {"name", bookName} + {"title", bookTitle}, + {"description", bookDescription}, + {"langCode", langCode}, + {"faviconAttr", faviconAttr} }); } return render_template( RESOURCE::templates::no_js_library_page_html, kainjow::mustache::object{ + {"root", rootLocation}, {"books", booksData } } ); diff --git a/static/templates/no_js_library_page.html b/static/templates/no_js_library_page.html index 0281d85ba..69f1c6ecc 100644 --- a/static/templates/no_js_library_page.html +++ b/static/templates/no_js_library_page.html @@ -29,12 +29,39 @@ font-family: "roboto"; src: url("{{root}}/skin/fonts/Roboto.ttf?KIWIXCACHEID") format("truetype"); } + + .book__list { + display: flex; + flex-direction: row; + flex-wrap: wrap; + align-items: center; + } + + .book__wrapper:hover { + transform: scale(1.0); + } - VERY REAL TEST :)))))))) - {{#books}} -
{{name}}
- {{/books}} +
+
+ {{#books}} +
+ + + +
{{langCode}}
+
TO DO: TAGS
+
+
+ {{/books}} +
+
\ No newline at end of file From c1d7cc37fd42b2708cbd2d17b597cf7a551d0a0d Mon Sep 17 00:00:00 2001 From: Nikhil Tanwar <2002nikhiltanwar@gmail.com> Date: Mon, 13 Feb 2023 18:12:49 +0530 Subject: [PATCH 05/14] Add tags in tiles for /nojs endpoint Adds span elements for tags --- src/html_dumper.cpp | 22 +++++++++++++++++++++- static/templates/no_js_library_page.html | 10 +++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/html_dumper.cpp b/src/html_dumper.cpp index 9122a723a..6674080a2 100644 --- a/src/html_dumper.cpp +++ b/src/html_dumper.cpp @@ -1,6 +1,7 @@ #include "html_dumper.h" #include "libkiwix-resources.h" #include "tools/otherTools.h" +#include "tools.h" namespace kiwix { @@ -15,6 +16,23 @@ HTMLDumper::~HTMLDumper() { } +namespace { + +kainjow::mustache::list getTagList(std::string tags) +{ + const auto tagsList = kiwix::split(tags, ";", true, false); + kainjow::mustache::list finalTagList; + for (auto tag : tagsList) { + if (tag[0] != '_') + finalTagList.push_back(kainjow::mustache::object{ + {"tag", tag} + }); + } + return finalTagList; +} + +} // unnamed namespace + std::string HTMLDumper::dumpPlainHTML() const { kainjow::mustache::list booksData; @@ -24,12 +42,14 @@ std::string HTMLDumper::dumpPlainHTML() const const auto bookDescription = bookObj.getDescription(); const auto langCode = bookObj.getCommaSeparatedLanguages(); const auto bookIconUrl = rootLocation + "/catalog/v2/illustration/" + bookId + "/?size=48"; + const auto tags = bookObj.getTags(); std::string faviconAttr = "style=background-image:url(" + bookIconUrl + ")"; booksData.push_back(kainjow::mustache::object{ {"title", bookTitle}, {"description", bookDescription}, {"langCode", langCode}, - {"faviconAttr", faviconAttr} + {"faviconAttr", faviconAttr}, + {"tagList", getTagList(tags)} }); } diff --git a/static/templates/no_js_library_page.html b/static/templates/no_js_library_page.html index 69f1c6ecc..2db51a0d6 100644 --- a/static/templates/no_js_library_page.html +++ b/static/templates/no_js_library_page.html @@ -40,6 +40,10 @@ .book__wrapper:hover { transform: scale(1.0); } + + .tag__link { + pointer-events: none; + } @@ -57,7 +61,11 @@
{{langCode}}
-
TO DO: TAGS
+
+ {{#tagList}} + {{tag}} + {{/tagList}} +
{{/books}} From dbded6eee2fc4497cfadd26055906b9a028e9f74 Mon Sep 17 00:00:00 2001 From: Nikhil Tanwar <2002nikhiltanwar@gmail.com> Date: Tue, 14 Feb 2023 00:32:22 +0530 Subject: [PATCH 06/14] Add links to content for tiles in /nojs If the tiles are now clicked, they redirect to main page of book. --- src/html_dumper.cpp | 5 +++++ static/templates/no_js_library_page.html | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/html_dumper.cpp b/src/html_dumper.cpp index 6674080a2..277dc92ec 100644 --- a/src/html_dumper.cpp +++ b/src/html_dumper.cpp @@ -39,12 +39,17 @@ std::string HTMLDumper::dumpPlainHTML() const for ( const auto& bookId : library->getBooksIds() ) { const auto bookObj = library->getBookById(bookId); const auto bookTitle = bookObj.getTitle(); + std::string contentId = ""; + try { + contentId = urlEncode(nameMapper->getNameForId(bookId)); + } catch (...) {} const auto bookDescription = bookObj.getDescription(); const auto langCode = bookObj.getCommaSeparatedLanguages(); const auto bookIconUrl = rootLocation + "/catalog/v2/illustration/" + bookId + "/?size=48"; const auto tags = bookObj.getTags(); std::string faviconAttr = "style=background-image:url(" + bookIconUrl + ")"; booksData.push_back(kainjow::mustache::object{ + {"id", contentId}, {"title", bookTitle}, {"description", bookDescription}, {"langCode", langCode}, diff --git a/static/templates/no_js_library_page.html b/static/templates/no_js_library_page.html index 2db51a0d6..3494bd74d 100644 --- a/static/templates/no_js_library_page.html +++ b/static/templates/no_js_library_page.html @@ -51,7 +51,7 @@
{{#books}}
- +