Merge pull request #200 from kiwix/improved_kiwix_serve_taskbar

Improved taskbar #160 #59
This commit is contained in:
Matthieu Gautier 2018-06-15 18:32:06 +02:00 committed by GitHub
commit 5c040d3ee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 18 deletions

View File

@ -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.

View File

@ -114,6 +114,18 @@ inline std::string _tostring(const T& value)
}
std::pair<kiwix::Reader*, kiwix::Searcher*>
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<kiwix::Reader*, kiwix::Searcher*>(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(&regexLock);
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(&regexLock);
}
@ -378,18 +401,6 @@ static struct MHD_Response* build_callback_response_from_entry(
return response;
}
std::pair<kiwix::Reader*, kiwix::Searcher*>
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<kiwix::Reader*, kiwix::Searcher*>(reader, searcher);
}
static struct MHD_Response* handle_meta(RequestContext* request)
{
std::string humanReadableBookId;

View File

@ -4,7 +4,7 @@
<div class="kiwix_searchform">
<form class="kiwixsearch" method="GET" action="__ROOT_LOCATION__/search" id="kiwixsearchform">
<input autocomplete="off" class="ui-autocomplete-input" id="kiwixsearchbox" name="pattern" type="text">
<input type="submit" value="Search">
<input type="submit" value="&#x1f50d;">
</form>
</div>
</div>

View File

@ -2,15 +2,15 @@
<span id="kiwixtoolbar" class="ui-widget-header">
<div class="kiwix_centered">
<div class="kiwix_button_wrapper">
<a id="kiwix_serve_taskbar_library_button" href="__ROOT_LOCATION__/"><button>Library</button></a>
<a id="kiwix_serve_taskbar_home_button" href="__ROOT_LOCATION__/__CONTENT__/"><button>Home</button></a>
<a id="kiwix_serve_taskbar_random_button" href="__ROOT_LOCATION__/random?content=__CONTENT_ESCAPED__"><button>Random</button></a>
<a id="kiwix_serve_taskbar_library_button" href="__ROOT_LOCATION__/"><button>&#x1f3e0;</button></a>
<a id="kiwix_serve_taskbar_home_button" href="__ROOT_LOCATION__/__CONTENT__/"><button>__ZIM_TITLE__</button></a>
<a id="kiwix_serve_taskbar_random_button" href="__ROOT_LOCATION__/random?content=__CONTENT_ESCAPED__"><button>&#x1F3B2;</button></a>
</div>
<div class="kiwix_searchform">
<form class="kiwixsearch" method="GET" action="__ROOT_LOCATION__/search" id="kiwixsearchform">
<input type="hidden" name="content" value="__CONTENT__" />
<input autocomplete="off" class="ui-autocomplete-input" id="kiwixsearchbox" name="pattern" type="text">
<input type="submit" value="Search">
<input type="submit" value="&#x1f50d;">
</form>
</div>
</div>