mirror of
https://github.com/kiwix/libkiwix.git
synced 2025-06-28 05:49:35 +00:00
Introduce a results intermediate object in the template rendering.
Url in href must not be html encoded. As we already url encode the path, it is ok to have `'` in the url.
This commit is contained in:
@ -164,28 +164,28 @@ kainjow::mustache::data buildPagination(
|
||||
std::string SearchRenderer::getHtml()
|
||||
{
|
||||
// Build the results list
|
||||
kainjow::mustache::data results{kainjow::mustache::data::type::list};
|
||||
|
||||
kainjow::mustache::data items{kainjow::mustache::data::type::list};
|
||||
for (auto it = m_srs.begin(); it != m_srs.end(); it++) {
|
||||
kainjow::mustache::data result;
|
||||
result.set("title", it.getTitle());
|
||||
result.set("url", it.getPath());
|
||||
result.set("snippet", it.getSnippet());
|
||||
std::string zim_id(it.getZimId());
|
||||
result.set("resultContentId", mp_nameMapper->getNameForId(zim_id));
|
||||
if (!mp_library) {
|
||||
result.set("bookTitle", kainjow::mustache::data(false));
|
||||
} else {
|
||||
result.set("title", it.getTitle());
|
||||
result.set("absolutePath", protocolPrefix + urlEncode(mp_nameMapper->getNameForId(zim_id), true) + "/" + urlEncode(it.getPath()));
|
||||
result.set("snippet", it.getSnippet());
|
||||
if (mp_library) {
|
||||
result.set("bookTitle", mp_library->getBookById(zim_id).getTitle());
|
||||
}
|
||||
|
||||
if (it.getWordCount() >= 0) {
|
||||
result.set("wordCount", kiwix::beautifyInteger(it.getWordCount()));
|
||||
}
|
||||
|
||||
results.push_back(result);
|
||||
items.push_back(result);
|
||||
}
|
||||
|
||||
kainjow::mustache::data results;
|
||||
results.set("items", items);
|
||||
results.set("count", kiwix::beautifyInteger(estimatedResultCount));
|
||||
results.set("hasResults", estimatedResultCount != 0);
|
||||
results.set("start", kiwix::beautifyInteger(resultStart+1));
|
||||
results.set("end", kiwix::beautifyInteger(min(resultStart+pageLength, estimatedResultCount)));
|
||||
|
||||
// pagination
|
||||
auto pagination = buildPagination(
|
||||
@ -194,26 +194,17 @@ std::string SearchRenderer::getHtml()
|
||||
resultStart
|
||||
);
|
||||
|
||||
auto resultEnd = min(resultStart+pageLength, estimatedResultCount);
|
||||
|
||||
kainjow::mustache::data query = buildQueryData(
|
||||
searchProtocolPrefix,
|
||||
searchPattern,
|
||||
searchContent
|
||||
);
|
||||
|
||||
|
||||
|
||||
std::string template_str = RESOURCE::templates::search_result_html;
|
||||
kainjow::mustache::mustache tmpl(template_str);
|
||||
|
||||
kainjow::mustache::data allData;
|
||||
allData.set("results", results);
|
||||
allData.set("hasResults", estimatedResultCount != 0);
|
||||
allData.set("count", kiwix::beautifyInteger(estimatedResultCount));
|
||||
allData.set("resultStart", to_string(resultStart + 1));
|
||||
allData.set("resultEnd", to_string(resultEnd));
|
||||
allData.set("protocolPrefix", this->protocolPrefix);
|
||||
allData.set("pagination", pagination);
|
||||
allData.set("query", query);
|
||||
|
||||
|
Reference in New Issue
Block a user