mirror of https://github.com/kiwix/libkiwix.git
Applied cache-id to search_results.css
The story of search_results.css static/skin/search_results.css was extracted from static/templates/no_search_result.html before the latter was dropped. static/templates/no_search_result.html in turn seems to be a copied and edited version of static/templates/search_result.html. In the context of exploratory work on the internationalization of kiwix-serve (PR #679) I noticed duplication of inline CSS across those two templates and intended to eliminated it. That goal was not fully accomplished (static/templates/search_result.html remained untouched) because by that time PR #679 grew too big and the efforts were diverted into splitting it into smaller ones. Thus search_results.css slipped into one of those small PRs, without making much sense because nothing really justifies preserving custom CSS in the "Fulltext search unavailable" error page. At the same time, it served as the only case where a link to a cacheable resource is generated in C++ code (rather than found in a template). This poses certain problems to the handling of cache-ids. A workaround is to expel the URL into a template so that it is processed by `kiwix-resources`. This commit merely demonstrates that solution. But whether it should be preserved (or rather the "Fulltext search unavailable" page should be deprived of CSS) is questionable.
This commit is contained in:
parent
fc85215ea0
commit
3b9f28b2b5
|
@ -43,7 +43,7 @@ def fill_resource_revisions(resource_file_path):
|
|||
for resource in read_resource_file(resource_file_path):
|
||||
resource_revisions[resource] = get_resource_revision(base_dir, resource)
|
||||
|
||||
RESOURCE_WITH_CACHEID_URL_PATTERN=r'"([^"?]+)\?KIWIXCACHEID([^"]*)"'
|
||||
RESOURCE_WITH_CACHEID_URL_PATTERN=r'([^"?]+)\?KIWIXCACHEID([^"]*)'
|
||||
|
||||
def set_cacheid(resource_matchobj):
|
||||
path = resource_matchobj.group(1)
|
||||
|
@ -53,7 +53,7 @@ def set_cacheid(resource_matchobj):
|
|||
resource = resource[len(root_prefix):]
|
||||
extra_query = resource_matchobj.group(2)
|
||||
cacheid = 'cacheid=' + resource_revisions[resource]
|
||||
return f'"{path}?{cacheid}{extra_query}"'
|
||||
return f'{path}?{cacheid}{extra_query}'
|
||||
|
||||
def preprocess_line(line):
|
||||
if 'KIWIXCACHEID' in line:
|
||||
|
|
|
@ -442,6 +442,16 @@ SuggestionsList_t getSuggestions(SuggestionSearcherCache& cache, const zim::Arch
|
|||
namespace
|
||||
{
|
||||
|
||||
std::string renderUrl(const std::string& root, const std::string& urlTemplate)
|
||||
{
|
||||
MustacheData data;
|
||||
data.set("root", root);
|
||||
auto url = kainjow::mustache::mustache(urlTemplate).render(data);
|
||||
if ( url.back() == '\n' )
|
||||
url.pop_back();
|
||||
return url;
|
||||
}
|
||||
|
||||
std::string makeFulltextSearchSuggestion(const std::string& lang, const std::string& queryString)
|
||||
{
|
||||
return i18n::expandParameterizedString(lang, "suggest-full-text-search",
|
||||
|
@ -622,10 +632,11 @@ std::unique_ptr<Response> InternalServer::handle_search(const RequestContext& re
|
|||
} catch(std::runtime_error& e) {
|
||||
// Searcher->search will throw a runtime error if there is no valid xapian database to do the search.
|
||||
// (in case of zim file not containing a index)
|
||||
const auto cssUrl = renderUrl(m_root, RESOURCE::templates::url_of_search_results_css);
|
||||
return HTTPErrorHtmlResponse(*this, request, MHD_HTTP_NOT_FOUND,
|
||||
"fulltext-search-unavailable",
|
||||
"404-page-heading",
|
||||
m_root + "/skin/search_results.css")
|
||||
cssUrl)
|
||||
+ nonParameterizedMessage("no-search-results")
|
||||
+ TaskbarInfo(searchInfo.bookName, archive.get());
|
||||
}
|
||||
|
|
|
@ -47,5 +47,6 @@ templates/catalog_v2_entries.xml
|
|||
templates/catalog_v2_entry.xml
|
||||
templates/catalog_v2_categories.xml
|
||||
templates/catalog_v2_languages.xml
|
||||
templates/url_of_search_results_css
|
||||
opensearchdescription.xml
|
||||
catalog_v2_searchdescription.xml
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{{root}}/skin/search_results.css?KIWIXCACHEID
|
|
@ -345,7 +345,7 @@ R"EXPECTEDRESULT(<link type="root" href="/ROOT"><link type="text/css" href="/ROO
|
|||
// Searching in a ZIM file without a full-text index returns
|
||||
// a page rendered from static/templates/no_search_result_html
|
||||
/* url */ "/ROOT/search?content=poor&pattern=whatever",
|
||||
R"EXPECTEDRESULT( <link type="text/css" href="/ROOT/skin/search_results.css" rel="Stylesheet" />
|
||||
R"EXPECTEDRESULT( <link type="text/css" href="/ROOT/skin/search_results.css?cacheid=76d39c84" rel="Stylesheet" />
|
||||
<link type="root" href="/ROOT"><link type="text/css" href="/ROOT/skin/jquery-ui/jquery-ui.min.css?cacheid=e1de77b3" rel="Stylesheet" />
|
||||
<link type="text/css" href="/ROOT/skin/jquery-ui/jquery-ui.theme.min.css?cacheid=2a5841f9" rel="Stylesheet" />
|
||||
<link type="text/css" href="/ROOT/skin/taskbar.css?cacheid=49365e9c" rel="Stylesheet" />
|
||||
|
@ -847,7 +847,7 @@ TEST_F(ServerTest, 404WithBodyTesting)
|
|||
|
||||
{ /* url */ "/ROOT/search?content=poor&pattern=whatever",
|
||||
expected_page_title=="Fulltext search unavailable" &&
|
||||
expected_css_url=="/ROOT/skin/search_results.css" &&
|
||||
expected_css_url=="/ROOT/skin/search_results.css?cacheid=76d39c84" &&
|
||||
book_name=="poor" &&
|
||||
book_title=="poor" &&
|
||||
expected_body==R"(
|
||||
|
|
Loading…
Reference in New Issue