mirror of https://github.com/kiwix/libkiwix.git
Add search form for /nojs endpoint
Adds an html form to search books by the q= parameter
This commit is contained in:
parent
0f7e11bd86
commit
a48e2e6f06
|
@ -42,7 +42,7 @@ class HTMLDumper : public LibraryDumper
|
|||
*
|
||||
* @return HTML content
|
||||
*/
|
||||
std::string dumpPlainHTML() const;
|
||||
std::string dumpPlainHTML(kiwix::Filter filter) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -33,10 +33,13 @@ kainjow::mustache::list getTagList(std::string tags)
|
|||
|
||||
} // unnamed namespace
|
||||
|
||||
std::string HTMLDumper::dumpPlainHTML() const
|
||||
std::string HTMLDumper::dumpPlainHTML(kiwix::Filter filter) const
|
||||
{
|
||||
kainjow::mustache::list booksData;
|
||||
for ( const auto& bookId : library->getBooksIds() ) {
|
||||
const auto filteredBooks = library->filter(filter);
|
||||
const auto searchQuery = filter.getQuery();
|
||||
|
||||
for ( const auto& bookId : filteredBooks ) {
|
||||
const auto bookObj = library->getBookById(bookId);
|
||||
const auto bookTitle = bookObj.getTitle();
|
||||
std::string contentId = "";
|
||||
|
@ -65,7 +68,8 @@ std::string HTMLDumper::dumpPlainHTML() const
|
|||
RESOURCE::templates::no_js_library_page_html,
|
||||
kainjow::mustache::object{
|
||||
{"root", rootLocation},
|
||||
{"books", booksData }
|
||||
{"books", booksData },
|
||||
{"searchQuery", searchQuery}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -783,7 +783,8 @@ std::unique_ptr<Response> InternalServer::handle_no_js(const RequestContext& req
|
|||
std::string content;
|
||||
|
||||
if (urlParts.size() == 1) {
|
||||
content = htmlDumper.dumpPlainHTML();
|
||||
const auto filter = get_search_filter(request);
|
||||
content = htmlDumper.dumpPlainHTML(filter);
|
||||
} else if ((urlParts.size() == 3) && (urlParts[1] == "download")) {
|
||||
try {
|
||||
const auto bookId = mp_nameMapper->getIdForName(urlParts[2]);
|
||||
|
@ -797,7 +798,6 @@ std::unique_ptr<Response> InternalServer::handle_no_js(const RequestContext& req
|
|||
+ urlNotFoundMsg;
|
||||
}
|
||||
|
||||
|
||||
return ContentResponse::build(
|
||||
*this,
|
||||
content,
|
||||
|
|
|
@ -61,6 +61,12 @@
|
|||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class='kiwixNav'>
|
||||
<form id='kiwixSearchForm' class='kiwixNav__SearchForm' action="{{root}}/nojs">
|
||||
<input type="text" name="q" placeholder="Search" id="searchFilter" class='kiwixSearch filter' value="{{searchQuery}}">
|
||||
<input type="submit" class="kiwixButton kiwixButtonHover" value="Search"/>
|
||||
</form>
|
||||
</div>
|
||||
<div class="kiwixHomeBody">
|
||||
<div class="book__list">
|
||||
{{#books}}
|
||||
|
|
Loading…
Reference in New Issue