From 8fccbc4c99ab4b13edbe9f7dddcdc50cc6d4c08e Mon Sep 17 00:00:00 2001 From: Kelson Date: Sun, 10 Jun 2018 19:39:53 +0200 Subject: [PATCH 1/2] Improved taskbar #160 #59 --- Changelog | 7 ++++++- src/server/kiwix-serve.cpp | 35 ++++++++++++++++++++++----------- static/server/taskbar.html.part | 8 ++++---- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/Changelog b/Changelog index 0070c42..7c39c31 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,11 @@ kiwix-tools 0.6.0 ================= +kiwix-serve +------------ + + * Improved taskbar #160 #59 + kiwix-manage ------------ @@ -13,7 +18,7 @@ kiwix-tools 0.5.0 * Compile without warning. -kiwix-server +kiwix-serve ------------ * Serve metadata information using the "/meta" url. diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index 9aac128..7a1a625 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -114,6 +114,18 @@ inline std::string _tostring(const T& value) } +std::pair +get_from_humanReadableBookId(const std::string& humanReadableBookId) { + kiwix::Searcher* searcher + = searchers.find(humanReadableBookId) != searchers.end() + ? searchers.find(humanReadableBookId)->second + : globalSearcher; + kiwix::Reader* reader = readers.find(humanReadableBookId) != readers.end() + ? readers.find(humanReadableBookId)->second + : NULL; + return std::pair(reader, searcher); +} + /* Try to get the mimeType from the file extension */ static std::string getMimeTypeForFile(const std::string& filename) { @@ -147,7 +159,10 @@ static bool startswith(const std::string& base, const std::string& start) void introduceTaskbar(string& content, const string& humanReadableBookId) { + string zimTitle; + pthread_mutex_lock(®exLock); + if (!noSearchBarFlag) { content = appendToFirstOccurence( content, @@ -169,10 +184,18 @@ void introduceTaskbar(string& content, const string& humanReadableBookId) RESOURCE::taskbar_html_part, humanReadableBookId, "__CONTENT__")); + + auto reader = get_from_humanReadableBookId(humanReadableBookId).first; + if (reader != nullptr) { + zimTitle = reader->getTitle(); + } } } + content = replaceRegex(content, rootLocation, "__ROOT_LOCATION__"); + content = replaceRegex(content, replaceRegex(zimTitle, "%26", "&"), "__ZIM_TITLE__"); content = replaceRegex(content, replaceRegex(humanReadableBookId, "%26", "&"), "__CONTENT_ESCAPED__"); + pthread_mutex_unlock(®exLock); } @@ -378,18 +401,6 @@ static struct MHD_Response* build_callback_response_from_entry( return response; } -std::pair -get_from_humanReadableBookId(const std::string& humanReadableBookId) { - kiwix::Searcher* searcher - = searchers.find(humanReadableBookId) != searchers.end() - ? searchers.find(humanReadableBookId)->second - : globalSearcher; - kiwix::Reader* reader = readers.find(humanReadableBookId) != readers.end() - ? readers.find(humanReadableBookId)->second - : NULL; - return std::pair(reader, searcher); -} - static struct MHD_Response* handle_meta(RequestContext* request) { std::string humanReadableBookId; diff --git a/static/server/taskbar.html.part b/static/server/taskbar.html.part index 40967af..3ea5226 100644 --- a/static/server/taskbar.html.part +++ b/static/server/taskbar.html.part @@ -2,15 +2,15 @@ From bb1afb512010f298bf593429a5fef011aa2f393a Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 15 Jun 2018 18:28:04 +0200 Subject: [PATCH 2/2] Also set magnify glass in the global taskbar. --- static/server/global_taskbar.html.part | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/server/global_taskbar.html.part b/static/server/global_taskbar.html.part index 31737b3..b19f852 100644 --- a/static/server/global_taskbar.html.part +++ b/static/server/global_taskbar.html.part @@ -4,7 +4,7 @@
- +